This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]