Re: [xsl] numbering nodes (by context | input), but not single ones

Subject: Re: [xsl] numbering nodes (by context | input), but not single ones
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 12 Apr 2002 18:48:16 +0100
Hi Markus,

> 1. But I can not exclude those subitems with attributes.
>
>         <subitem typ="foo">not here</subitem>
>
> See bottom of testNumber.xsl :

The problem here is that you're doing:

  preceding-sibling::subitem[@typ != 'foo']

which selects only those preceding sibling subitem elements that have
a typ attribute whose value is not equal to 'foo', and thus excludes
all the subitem elements that don't have a typ attribute.

I suspect that you want to do:

  preceding-sibling::subitem[not(@typ = 'foo')]

which selects only those preceding sibling subitem elements that do
not have a typ attribute whose value is equal to 'foo', and thus
includes all the subitem elements that don't have a typ attribute.

> 2. Does this cost a lot, and if yes is there a cheaper method?
>
>     <xsl:if test="preceding-sibling::* or following-sibling::*">
>       <xsl:value-of select="concat(' ', count(preceding-sibling::*) + 1)"/>
>     </xsl:if>

The test would probably be cheaper as:

  <xsl:if test="../*[2]">
    ...
  </xsl:if>

in other words, "is there a second child of my parent"?

If you can use position() you should use position() instead to give
the numbering, but that requires you to apply templates to the
elements that you want to number, and only those elements, which might
not be practical.

> I guess xslt 2.0 would save me from all that hazzle... Unfortunately
> I am restricted to xalan.

Actually I don't think that XSLT 2.0 will be adding anything new in
this department. What changes to XSLT or XPath do you think would help
you achieve what you're trying to do more easily?

Cheers,

Jeni

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


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


Current Thread