[Home] [By Thread] [By Date] [Recent Entries]
On 16.05.2019 20:59, Rick Quatro rick@xxxxxxxxxxxxxx wrote:
I have a look up file of find/change pairs that I have to apply to a text node in my XML document. I am using XSLT 2. Here is an example of the lookup file:
There could be any number of <findchange> elements in my lookup file. Any pointers would be appreciated. Thank you very much. The examples seem to "upper case" the search strings so doing e.g. <xsl:variable name="pattern" as="xs:string"
select="string-join(doc('lookup.xml')/findchange_lookup/findchange/@find,
'|')"/> <xsl:template match="foo/text()">
<xsl:analyze-string select="." regex="{$pattern}">
<xsl:matching-substring>
<xsl:value-of select="upper-case(.)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>Or declare a key <xsl:key name="lookup" match="findchange" use="@find"/> and <xsl:template match="foo/text()">
<xsl:analyze-string select="." regex="{$pattern}">
<xsl:matching-substring>
<xsl:value-of select="key('lookup', .,
doc('lookup.xml'))/@change"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>Not sure if that suffices or if you need to replace one term recursively in the replacement of a previous term. And of course depending on the "find" values, to build the regular expression pattern, you might need to escape metacharacters first, I think functx has a function for that.
|

Cart



