xsl-list
[Top] [All Lists]

Re: [xsl] Merging multiple documents and combining their nodes

2007-06-13 10:38:31
Thanks Martin!

David:

Is the following what you had in mind?  The first template retrieves
the components/component node-sets from the files listed in the
filenames_file.xml document. The template defines this node-set as the
temp variable.

The second template organizes the information in the temp variable.

<xsl:stylesheet version="1.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
         xmlns:exslt="http://exslt.org/common";>
        <xsl:output indent="yes"/>
        <xsl:template match="/">
                <xsl:variable name="temp">
                        <components>
                                <xsl:copy-of
select="document(document('filenames_file.xml')/files/file)/components/component"/>
                        </components>
                </xsl:variable>
        </xsl:template>   
        
        <xsl:template match="/">
                <components>
                        <xsl:for-each 
select="exslt:node-set($temp)/components/component">
                                <xsl:sort select="@name"/>
                                        <name>
                                                <xsl:value-of select="@name"/>
                                        </name>
                                       ..
                        </xsl:for-each>
                </components>
        </xsl:template>
</xsl:stylesheet>


When I apply the stylesheet, Xalan displays an error: "Could not find
variable with the name of temp."  I presume the error is arising
because the second template cannot find the temp variable defined in
the first template. Would you agree?  If so, how could the issue be
resolved?

Thanks,
Mark


in that case I'd do it in two passes, first pull in all the elements
into one tree:

<xsl:variable name="temp">
<components>
 <xsl:copy-of
select="document(document('filenames_file.xml')/files/file)/components/component"/>
</components>
</xsl:variable>

then use exslt:node-set so you can apply templates to that to do the
grouping (eg muenchian grouping using keys as described in the faq or
jeni's site. this is much easier now that all the nodes to be grouped
are siblings of each other.

<components>
<xsl:for-each select="exslt:node-set($temp)/components/component[.....
....
</xsl:for-each>
</components>

David

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--