Re: [xsl] Generating numbering for cross-references (LONG)

Subject: Re: [xsl] Generating numbering for cross-references (LONG)
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Thu, 18 Oct 2001 10:33:01 +0200
Peter Flynn <peter@xxxxxxxxxxx> wrote:
[snip]
General comment: I've done something like this.
Other comments:
>    i) how do you combine locating the element with the right ID *and*
>       counting its preceding siblings in the same XPath expression,
Why do you want single a XPath? Use xsl:call-template, you can have
variables there.
   <xsl:template match="ref">
     ...
     <xsl:call-template name="get-number"/>
     ...

   <xsl:template name="get-number">
     <xsl:variable name="target" select="key('id',@id)"/>
     <xsl:number value="count($target/preceding-sibling[name()=name($target)])+1"/>
    ...

You can insert an xsl:choose to check whether the referenced item
exists and is unique by test"count($target)=1" and provide fallbacks or
error messages for other cases.

>   ii) ...you cannot use name() to formulate a dynamic expression as in
>       count(preceding-sibling::name(ID(@to)))
Try count(preceding-sibling::*[name()=current()/name(ID(@to))])

> iii) if this is to work on non-validating parsers, we must use an
>       expression like //*[id=$thisref] instead of ID(@to),...
Unlearn ID/id(). Use xsl:key/key() instead.
  <xsl:key name="table-id" match="table" use="@id"/>

>   iv) / v) 
At this point often a two-stage approach is suggested.
  <xsl:variable name="stage-1-result">
    <xsl:apply-templates select="/" mode="add-numbering"/>
  </xsl:variable>
  <xsl:apply-templates select="xx:node-set($stage-1-result)"/>
...
  <xsl:template match="*" mode="add-numbering">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:attribute name="stage-1-number">
        <xsl:number level="all"/>
      </xsl:attribute>
      <xsl:apply-templates select="node()" mode="add-numbering"/>
    </xsl:copy>
  </xsl:template>

HTH
J.Pietschmann

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


Current Thread