create on output multiple xml files
Posted: Tue Feb 12, 2013 10:25 pm
Hi, I'm very new to transformation scenarios. I'm practicing with a test xml file (see below). What I would like is to create multiple .xml files where each <cd> and its children and information is in a new cd_{position #}.xml file. I've tried using xsl:result-document (see below). In the results, all I get is the following:
<?xml version="1.0" encoding="UTF-8"?> and no files are written to my folder where my xml and xsl files are located. I've also tried using the extension for xslt 1.0 and the result is again nothing written in my folder but the ext:document shows up in my results. I'd prefer to figure this out with xslt 2.0 and xsl:result-document. Any help would be much appreciated.
Thanks,
Jen
xml file:
xslt file:
<?xml version="1.0" encoding="UTF-8"?> and no files are written to my folder where my xml and xsl files are located. I've also tried using the extension for xslt 1.0 and the result is again nothing written in my folder but the ext:document shows up in my results. I'd prefer to figure this out with xslt 2.0 and xsl:result-document. Any help would be much appreciated.
Thanks,
Jen
xml file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" encoding="UTF-8" indent="yes" name="xml"/>
<xsl:template match="/">
<xsl:for-each select="cd">
<xsl:result-document method="xml" href="cd_{position()}.xml" encoding="UTF-8" indent="yes">
<catalog>
<xsl:copy-of select="."/>
</catalog>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>