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

Re: determining position of a document included using

Subject: Re: determining position of a document included using document function
From: "Gennady Loskutov" <g_loskutov@xxxxxxxxxxxxx>
Date: Thu, 14 Feb 2002 11:03:09 +0100
loskutov
> is there anyway to find out the position of file in the root document,
> without trying to do <xsl:apply-templates>
> <xsl:with-param name="filepos" select="position()"/>
> </xsl:apply-templates>

Bryan,

I use generate-id() function to identify the included file. Basically, the
idea is to match generated id for the root element of the current node with
ones, generated separately and stored in a variable. According to XSLT spec,
generate-id(document("foo.xml"))=generate-id(document("foo.xml")) is always
true, so I assume that
generate-id(document("foo.xml"))=generate-id(document(/files/file/@href))
must be also true if the "foo.xml" file is among those specified in
/files/file/@href.

To use my solution, you must use an extension function to transform a result
tree fragment stored in a variable into a node set (I use Microsoft XML
parser, which has node-set() function).

For example, using the following XML file

<?xml version="1.0" ?>
<files>
   <file href="data1.xml" />
   <file href="data2.xml" />
   <file href="data3.xml" />
</files>

I declare a variable, which is a union of the documents
<xsl:variable name="merged" select="document(/files/file/@href)" />

Then I store generated id for each document root in another variable:

<xsl:variable name="tops">
 <xsl:for-each select="/files/file">
  <file>
   <xsl:copy-of select="@href" />
   <xsl:attribute name="id"><xsl:value-of
select="generate-id(document(@href))" /></xsl:attribute>
  </file>
 </xsl:for-each>
</xsl:variable>

When I need to know the file URL, I do the following:
<xsl:template match="myElement">
...
 <xsl:variable name="currentTop" select="generate-id(/)" />
 <url>
  <xsl:value-of select="msxsl:node-set($tops)/file[@id = $currentTop]/@href"
/>
 </url>

Regards,
Gennady


 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.