This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Generating numbering for cross-references (LONG)
- To: XSL List <xsl-list at lists dot mulberrytech dot com>
- Subject: Re: [xsl] Generating numbering for cross-references (LONG)
- From: Joerg Pietschmann <joerg dot pietschmann at zkb dot ch>
- Date: Thu, 18 Oct 2001 10:33:01 +0200
- Organization: ZKB
- Reply-To: xsl-list at lists dot mulberrytech dot com
Peter Flynn <peter@silmaril.ie> 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