xsl-list
[Top] [All Lists]

RE: Xref numbering test

2003-12-16 12:41:36
At 08:27 AM 12/16/2003, Andrew wrote:
First build a nodeset of all the <stepX>'s with their id's and how you
want to number them:

<xsl:variable name="steps">
  <xsl:for-each select="//step1|//step2|....|//step9">
    <step id="{(_at_)id}">
      <xsl:attribute name="number">
        <xsl:number count="step1|step2....|

And so on.

This will give you a variable holding something like:

<step id="1234" number="1."/>
<step id="1abc2" number="1.1."/>

Then in your step processing template, query the variable for the
correct number using the id of the step you are processing:

<xsl:template match="step1|step2...">
  <xsl:variable name="currentId" select="@id"/>
  <xsl:for-each select="$steps">
    <xsl:value-of select="step[(_at_)id = $currentId]/@number"/>

1. This will only work when using XSLT 2.0, or a node-set extension function, since ordinarily (in XSLT 1.0) you cannot iterate over, or query into, a result-tree-fragment this way.

2. Even so, how is it better than simply calculating the number of each step using the same <xsl:number count="step1|step2|..." ... /> instruction, where you need it?

<xsl:template match="step1|step2...">
  <xsl:variable name="currentId" select="@id"/>
  <xsl:for-each select="$steps">
    <xsl:value-of select="step[(_at_)id = $currentId]/@number"/>
    ...

could as easily be

<xsl:template match="step1|step2...">
  <xsl:number count="step1|step2....| " .../>

(Look ma, no variable.)

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>