Page 1 of 1
create single output files
Posted: Fri May 13, 2011 4:27 am
by stattersall
I am new to oxygen and I have setup a custom transformation scenario to transform multiple xml files with a single xslt stylesheet. Instead of creating multiple output files following the transformation, I want to merge all transformation into a single .html output file.
Can someone advise on this please.
regards,
Steve Tattersall
Re: create single output files
Posted: Fri May 13, 2011 9:59 am
by Radu
Hi Steve,
XSLT 2.0 has support for processing multiple XML input files and Oxygen comes bundled with the Saxon 9 Enterprise Edition XSLT processor which has full XSLT 2.0 support. The XSLT 2.0 function you can use is called
collection().
So for example if your XML files have the following structure:
Code: Select all
<root>
<person>
.....
</person>
.....
<person>
.....
</person>
.....
</root>
a sample XSLT 2.0 stylesheet like:
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:template match="/">
<html>
<body>
<!-- Iterate all XML files in the "file:/D:/projects/eXml/samples/" directory and get all "person" elements from them -->
<xsl:variable name="allPersons" select="collection('file:/D:/projects/eXml/samples/?select=*.xml')//person"/>
<xsl:for-each select="$allPersons">
<!--Here you can match each person and output HTML from it-->
<xsl:copy-of select="."/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
would iterate all your XML files from a certain directory and gather with an XPath all
<person> elements from them.
You can apply the XSLT stylesheet on any XML file as it will only be interested in processing the files in the collection.
Regards,
Radu