I am trying to create an stylesheet to transform an XML to other format of an XML and in the process it should create multiple XML files that are placed in separate folders. The XML file I am trying to work with is very large(~50000 lines) and I want to automate it. The XML i want to transforme looke like so
XML:
<Site>
<View name="big_bang">
<Element name="Galaxy">
<Property value="milky_way"/>
<Element localizedName="Earth">
<Property localizedName="Adresse" value="1"/>
</Element>
</Element>
</View>
<View name="more_big_bang">
<Element name="Galaxy">
<Property value="orion"/>
<Element localizedName="otherEarth">
<Property localizedName="otherAdresse" value="10"/>
</Element>
</Element>
</View>
</Site>
XSLT:
<xsl:template match="Outside">
<xsl:apply-templates select="//Site"/>
</xsl:template>
`<xsl:template match="Site">
<xsl:result-document method="xml" href="{string-join(ancestor-or-self::Site/@name, '/')}/test.xml">
<GraphicsTree>
<xsl:copy-of select="."/>
</GraphicsTree>
</xsl:result-document>
</xsl:template>`
XSLT should create folder for each child node with the name of the value of name or localizedName So each folder should have small XML in it with the copy of Property. But instead of that i get one foder and one XML file in it with whole xml file copied to it. I also use SAXON Processor.
<Element localizedName="foo"/>, then you would indeed get an error as the code would try to create a file namedfoo.xmlin the same folder twice. You will need to explain how you want to handle that case.Siteelement in your input sample so of course a template withmatch="Site"that then has onexsl:result-documentinstruction will create a single output file and if you have anxsl:copy-of select="."then you copy theSiteelement to that output file. So you need to decide for which elements you want to create an output file, write a template matching them, as shown in my answer to your previous question, and then put thexsl:result-documentin that template.