开发者

How do I conditionally copy XML elements using XSLT?

开发者 https://www.devze.com 2023-01-13 05:33 出处:网络
I am trying to conditionally copy nodes using XSL.Here is my XML: <root> <node_a>111</node_a>

I am trying to conditionally copy nodes using XSL. Here is my XML:

<root>
    <node_a>111</node_a>
    <node_b>222</node_b>
    <node_c>333</node_c>
</root>

How do I just copy all the nodes EXCEPT for "node_a" using开发者_如何学JAVA XSLT?

TIA


Use an identity transform plus an empty template matching node_a.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="node_a"/>
</xsl:stylesheet>

Works in both XSLT1 and XSLT2

0

精彩评论

暂无评论...
验证码 换一张
取 消