下面的XSLT提取**
并将其拷贝之间的COPY VALUE
串到<payload>
标签的末端。然后COPY VALUE
之前和之后的字符串将用作<copied>
标记的前缀和后缀。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="payload">
<xsl:variable name="copyval" select="substring-before(substring-after(test/text(),'**'),'**')" />
<xsl:variable name="valBefore" select="substring-before(test/text(),$copyval)" />
<xsl:variable name="valAfter" select="substring-after(test/text(),$copyval)" />
<xsl:copy>
<test><xsl:value-of select="$copyval" /></test>
<xsl:apply-templates select="node()[not(self::test)]|@*" />
<xsl:value-of select="$valBefore" /><copied><xsl:value-of select="$copyval" /></copied><xsl:value-of select="$valAfter" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我不认为那些星号真的存在。我不认为'node()[local-name()!='test']'是很好的做法 - 我会使用'node()[not(self :: test)]''。如果有必要的话。 –
@ michael.hor257k:我用你建议的更好的做法改进了我的答案。关于星号:是的,我也想知道。但是这是所问的问题,我试图回答它给出的。如果作者对此发表评论,如果需要,我可以轻松删除这些行。 – zx485