Dynamically include XML files using XSLT -
i trying merge multiple xml files 1 in following manner:
say have xml file, called fruit.xml
:
<fruit> <apples> <include ref="apples.xml" /> </apples> <bananas> <include ref="bananas.xml" /> </bananas> <oranges> <include ref="oranges.xml" /> </oranges> </fruit>
and subsequent xml files referenced fruit.xml
, example apples.xml
:
<fruit> <apples> <apple type="jonagold" color="red" /> <... /> </apples> </fruit>
and on... merge these 1 xml file, such:
<fruit> <apples> <apple type="jonagold" color="red" /> <... /> </apples> <bananas> <banana type="chiquita" color="yellow" /> <... /> </bananas> <oranges> <orange type="some-orange-type" color="orange" /> <... /> </oranges> </fruit>
i want determine "child" files (like apples.xml
, bananas.xml
, etc.) dynamically based on values of ref
attributes in <include>
elements of fruits.xml
, include them in output.
is possible using xslt?
if contend of file should included can use:
<xsl:copy-of select="document(@ref)/fruit/*/*"/>
therefore try this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" > <xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes" /> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="include"> <xsl:copy-of select="document(@ref)/fruit/*/*"/> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment