I have this XML in one file below
cont
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>