Hello everybody,
This question is an extension of this one. I have many values, as seen below:
<myStuff>
<elem1>asdf</elem1>
<elem2>foo bar</elem2>
<elem3>foo bar foo</elem3>
<elem4>foofoo</elem4>
</myStuff>
I've been doing a copy-of
over MOST the elems (the select
in the copy-of
is very specific) and then doing a find-and-replace on the resulting XML, but I'd like to combine the two. In most of the situations where I've applied this, I would replace anything that said <xsl:value-of select="whatever">
with <xsl:apply-templates select="whatever">
and use the below template:
<xsl:template match="*">
<xsl:variable name="rep1">
<xsl:choose>
<xsl:when test='matches(., ".*foo.*")'>
<xsl:value-of select='replace(., "foo", "qwerty")' />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='./text()' />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="rep2">
<xsl:choose>
<xsl:when test='matches(., ".*bar.*")'>
<xsl:value-of select='replace($rep1, "bar", "myBar")' />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$rep1' />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$rep2" />
</xsl:template>
I would like to use a similar template to replace the copy-of
in my code (because I'm making the same replacements as in my other files, so I could use the same template), but I'm unsure of how to do this.
The output would look like this:
<myOtherStuff>
<elem1>asdf</elem1>
<elem2>qwerty myBar</elem2>
<elem3>qwerty myBar qwerty</elem3>
<elem4>qwertyqwerty</elem4>
</myOtherStuff>
All help is appreciated and thanks in advance!