[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: import Traversal

Subject: Re: import Traversal
From: Gary L Peskin <garyp@xxxxxxxxxxxx>
Date: Tue, 24 Oct 2000 20:35:43 -0400 (EST)
xsl param as a object
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.