如何使用xslt转换更改注释

时间:2015-01-07 05:14:15

标签: xml xslt xslt-2.0 xpath-2.0

<article>
    <articleInfo>
        <journalCode>ABC</journalCode>
        <articleNo>456</articleNo>
    </articleInfo>
    <body>
        <heading><!--This article contain 1 heading-->Heading 1</heading>
        <p>α-index</p>
        <p>This is para 2</p>
        <p>This is para 3</p>
        <p>This is para 4</p>
        <p>This is para 5</p>
    </body>
</article>

如何使用xslt更改注释文本 我还想提前将

1 个答案:

答案 0 :(得分:0)

您可以使用以下XSLT:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@* | *">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="text()[contains(.,'α-index')]">
    <xsl:value-of select="replace(., 'α-index', 'index 1')"/>
</xsl:template>

<xsl:template match="comment()">
    <xsl:comment>This heading was the only 1 heading in article</xsl:comment>
</xsl:template>
</xsl:stylesheet>

您可以根据自己的要求更改第二个模板(匹配text())。