Subject: Re: import Traversal From: Gary L Peskin <garyp@xxxxxxxxxxxx> Date: Tue, 24 Oct 2000 20:35:43 -0400 (EST) |
Benoit Cerrina wrote: > Now I'm processing the document "a" > I'd like to get: > <object id=1> > ABC > </object> Benoit -- This will produce the results you desired for the input you supplied. I took a little different approach which required the nodeset extension. First, I navigate through all of the doc elements in the various documents and build a nodeset consisting of all of the object elements. Then, I process the object elements in the main document but do not process multiple object elements with the same id. If you want to have multiple object elements with the same id, I think you could jazz the stylesheet up a little bit to create object elements which have the source document as an attribute or value. Then, you can eliminate elements if they come from the same document, using the Muenchian method. If you're interested in this and can't work it out, let us know. <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nodeset="org.apache.xalan.xslt.extensions.Nodeset" exclude-result-prefixes="nodeset"> <!--main template--> <xsl:template match="/"> <!-- Step one: Gather all object elements --> <xsl:variable name="all-objects"> <xsl:apply-templates select="doc"/> </xsl:variable> <!-- Step two: Process object elements from the primary document --> <xsl:apply-templates select="doc/object"> <xsl:with-param name="objects" select="nodeset:nodeset($all-objects)/object"/> </xsl:apply-templates> </xsl:template> <!-- This template accumulates all of the option elements --> <xsl:template match="doc"> <xsl:param name="visitedDocs" select="empty"/> <xsl:variable name="imported-objects"> <xsl:apply-templates select="document(import/@name[not(. = $visitedDocs)])/doc"> <xsl:with-param name="visitedDocs" select="$visitedDocs | @name"/> </xsl:apply-templates> </xsl:variable> <xsl:copy-of select="object | nodeset:nodeset($imported-objects)"/> </xsl:template> <!-- This template processes the top object elements --> <xsl:template match="object"> <xsl:param name="objects"/> <object id="{@id}"> <xsl:value-of select="@payload"/> <xsl:apply-templates select="$objects[@id = current()/@ref][1]" mode="payload"> <xsl:with-param name="objects" select="$objects"/> </xsl:apply-templates> </object> </xsl:template> <!-- And this template processes the referred-to object elements --> <xsl:template match="object" mode="payload"> <xsl:param name="objects"/> <xsl:value-of select="@payload"/> <xsl:apply-templates select="$objects[@id = current()/@ref][1]" mode="payload"> <xsl:with-param name="objects" select="$objects"/> </xsl:apply-templates> </xsl:template> --> </xsl:stylesheet> Gary XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
import Traversal, Benoit Cerrina | Thread | XSL-List mail loop, XSL-List Owner |
Re: need xsl for collapsed treeview, Robert Koberg | Date | Re: sum function, David Carlisle |
Month |