Hi, I'm working on a XSLT transformation that consists on merging two XML and then transform the result using another template. The idea is that depending on a field of the original XML file, the secong XML changes. For example:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<information>
<stmtinfo>
<type>80</type>
<language>2</language>
<clientnum>15907</clientnum>
<clientname>bogus</clientname>
<clientaddress>1401 Barnacle Street, Miami, Fl</clientaddress>
</stmtinfo>
</information>
</data>
depending on the value of the language node (let's call it LANG), a file callled language{LANG}.xml should appended. The content of those files is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<labels>
<l1001>cliente</l1001>
<l1002>moneda de referencia</l1002>
</labels>
into something like this:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<information>
<stmtinfo>
<type>80</type>
<language>2</language>
<clientnum>15907</clientnum>
<clientname>bogus</clientname>
<clientaddress>1401 Barnacle Street, Miami, Fl</clientaddress>
</stmtinfo>
</information>
<labels>
<l1001>cliente</l1001>
<l1002>moneda de referencia</l1002>
</labels>
</document>
And the result of that should be transformed. I have created the following template to do the merge:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xalan="http://xml.apache.org/xalan" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:java="http://xml.apache.org/xalan/java/java.lang" xmlns:xfc="http://www.metafocus.no/digiforms/component">
<xsl:template match="data">
<document>
<xsl:call-template name="copy"/>
<xsl:variable name="label_file_name" select="concat('Labels_',information/stmtinfo/language,'.xml')"/>
<xsl:variable name="labels">
<xsl:copy-of select="document($label_file_name)"/>
</xsl:variable>
<xsl:for-each select="xalan:nodeset($labels)/node()">
<xsl:call-template name="copy"/>
</xsl:for-each>
</document>
</xsl:template>
<xsl:template name="copy">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
If I user that template, I obtain the following:
<?xml version="1.0" encoding="UTF-8"?><document xmlns:xfc="http://www.metafocus.no/digiforms/component" xmlns:java="http://xml.apache.org/xalan/java/java.lang" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xalan="http://xml.apache.org/xalan"><data>
<information>
<stmtinfo>
<type>80</type>
<language>2</language>
<clientnum>15907</clientnum>
<clientname>bogus</clientname>
<clientaddress>1401 Barnacle Street, Miami, Fl</clientaddress>
</stmtinfo>
</information>
</data><labels>
<l1001>cliente</l1001>
<l1002>moneda de referencia</l1002>
</labels></document>
Which seems correct. But if I invocated from other template, to process the resulting XML
<xsl:template match="/">
<xsl:variable name="link1">
<xsl:apply-templates mode="link1" select="node()"/>
</xsl:variable>
<xsl:value-of select="xalan:nodeset($link1)"/>
</xsl:template>
I'm obtaining the following
80 2 15907 bogus 1401 Barnacle Street, Miami, Fl
So it seems that the merge does not work correctly, since if I convert the result to a nodeset, the node "labels" disappears. What I'm doing wrong?
Thank you very much.
Jose