下面的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