【问题标题】:How to transform change comment using xslt如何使用 xslt 转换更改注释
【发布时间】:2015-01-07 05:14:15
【问题描述】:
<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 更改评论文本 我也想提前将 a-index 替换为 α

【问题讨论】:

  • w3.org/1999/XSL/Transform" xmlns:xs="@987654322 @" xmlns:fn="w3.org/2005/xpath-functions" xmlns:xdt="w3.org/2005/xpath-datatypes" xmlns:err="w3.org/2005/xqt-errors" exclude-result-prefixes="xs xdt err fn">
  • 我希望我的输出是这样的
    ABC 456标题1

    α-index

    这是第 2 段

    这是第 3 段

    这是第 4 段

    这是第 5 段

  • 其实你可以编辑你的问题来放置你的代码和输出。顺便说一句,您的预期输出中的 &amp;alpha; 是什么。它不是一个正确的转义字符。

标签: xml xslt xslt-2.0 xpath-2.0


【解决方案1】:

您可以使用以下 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>

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-13
    • 2019-05-30
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 2019-03-04
    相关资源
    最近更新 更多