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

Re: xrefs (count,preceding,keys,node-set)

Subject: Re: xrefs (count,preceding,keys,node-set)
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 15 Apr 2002 17:25:02 +0100
count preceding
Hi Andrew,

> I need to tie the two together based on the @id. The xref needs to
> take the number given to its corresponding figure based on its
> position within all the figure's [ie. count(preceding::figure|.)]
>
> How do find I the correct number when I am processing the xref
> element?

You should create a key to index the figure elements by their id:

<xsl:key name="figures" match="figure" use="@id" />

Then you can quickly get from the current xref to the relevant figure
by calling the key function:

  key('figures', @id)

And from that create a number based on the number of preceding
figures:

  count(key('figures', @id)/preceding::figure) + 1

> This kind of linking has to be done several times in each file and
> really could do with being as fast as possible - is there a better
> way of doing this using keys, or by building a name-value node-set
> and using the node-set extention?

Hmm... using the preceding axis to create the numbers is pretty slow,
so that's what I'd target. One possibility would be to create a global
result tree fragment that contained information about each figure, its
number and ID:

<xsl:variable name="figures-rtf">
  <xsl:for-each select="//figure">
    <figure id="{@id}" number="{position()}" />
  </xsl:for-each>
</xsl:variable>

You can then convert this result tree fragment to a node set using an
extension function:

<xsl:variable name="figures" select="exsl:node-set($figures-rtf)" />

And then you can retrieve the number from that figure list, again
using the key (though it's more complicated this time because the
figures that you're looking at are in a different 'document' from the
xref elements):

<xsl:template match="xref">
  <xsl:variable name="id" select="@id" />
  <xsl:for-each select="$figures">
    <xsl:value-of select="key('figures', $id)/@number" />
  </xsl:for-each>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.