这个问题是这个问题的延伸。我有很多价值观,如下所示:
<myStuff>
<elem1>asdf</elem1>
<elem2>foo bar</elem2>
<elem3>foo bar foo</elem3>
<elem4>foofoo</elem4>
</myStuff>
我一直在做一个copy-of
over MOST the elems (the select
in thecopy-of
非常具体),然后对生成的 XML 进行查找和替换,但我想将两者结合起来。在我应用这个的大多数情况下,我会用下面的模板替换所说的任何<xsl:value-of select="whatever">
内容<xsl:apply-templates select="whatever">
:
<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>
我想使用类似的模板来替换copy-of
我的代码中的 (因为我正在做与其他文件相同的替换,所以我可以使用相同的模板),但我不确定如何做到这一点。
输出将如下所示:
<myOtherStuff>
<elem1>asdf</elem1>
<elem2>qwerty myBar</elem2>
<elem3>qwerty myBar qwerty</elem3>
<elem4>qwertyqwerty</elem4>
</myOtherStuff>
感谢所有帮助,并提前感谢!