Split one XML file to multiple XML File with XSLT

前端 未结 1 1221
生来不讨喜
生来不讨喜 2021-01-29 05:43

I have this XML in one file below



   
    cont         


        
相关标签:
1条回答
  • 2021-01-29 05:56

    With XSL 2.0:

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
            <xsl:for-each select="document/file">
                <xsl:result-document href="file{position()}.xml">
                    <document>
                        <xsl:copy-of select="current()"/>
                    </document>
                </xsl:result-document>
            </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>
    

    I tested this using Saxon, which supports XSLT 2.0, using the command below:

    java -jar saxon9.jar -xsl:transform.xsl -s:input.xml
    

    This command generates three files: file1.xml, file2.xml and file3.xml.

    $ cat file1.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <document>
       <file> <!--File1.xml-->
        <content>content file 1</content>
      </file>
    </document>
    
    0 讨论(0)
提交回复
热议问题