Using XSLT to copy all nodes in XML, with support for special cases

后端 未结 2 1059
独厮守ぢ
独厮守ぢ 2020-12-12 20:49

Say I have a large XML file that the following structure:


  
    1234
    abc         


        
相关标签:
2条回答
  • 2020-12-12 21:53

    Start with an identity transform, and include a template match for your exception.

    0 讨论(0)
  • 2020-12-12 21:55
    <?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>
    
    0 讨论(0)
提交回复
热议问题