XSLT:在节点值中保留html标记并应用模板

时间:2014-08-06 10:23:37

标签: xslt xslt-1.0

<sectiondiv>
    <p>
        <ph linebreak="true">
            Lorem<br/>&#160;&#160;Ipsum<br/>&#160;&#160;&#160;&#160;<br/><br/><br/><br/><br/><br/><br/>
        </ph>
    </p>
    <p>
        <ph image-relation="test" linebreak="true“>
            Lorem<br/><br/>Ipsum:<br/><br/>testsentence<br/><myref kind="Variable" type="PlainText">1 684 463 394</myref ><br/><br/>
        </ph>
    </p>
</sectiondiv>

我想转换此XML并在多个节点中保留HTML标记。 另外,我想在值上应用其他模板,例如myref标签有自己的模板。

有任何建议如何实现?

1 个答案:

答案 0 :(得分:0)

使用identity transformation

可以实现元素的“保存”
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>  
</xsl:template>

如果要对某些标记执行其他转换,请将这些模板放在标识转换模板之前,如下所示:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="myref">
    <strong>myref encountered!</strong>
  </xsl:template>

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