微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用XSLT复制XML中的所有节点,并支持特殊情况

我有一个大的XML文件,具有以下结构:
<MyXml>
  <Data1>
    <Node1>1234</Node1>
    <Node2>abc<Node2>
    <Node3>gfdf</Node3>
    ...
    <Node10000>more text</Node10000>
  </Data1>
  <Data2>
    ...
  </Data2>
</MyXml>

我想将这个XML转换成另外一个看起来完全一样的XML,但是有一个连接到特定节点的字符串,比如Node766。我正在使用XSLT,并且想知道如何按照原样复制每个按钮,除了Node766,在输出之前我必须先做一些事情。

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--Identity template,provides default behavior that copies all content into the output -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <!--More specific template for Node766 that provides custom behavior -->
    <xsl:template match="Node766">  
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
            <!--Do something special for Node766,like add a certain string-->
            <xsl:text> add some text </xsl:text>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>

原文地址:https://www.jb51.cc/xml/293448.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。