This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: a nicer total sibling count than this
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: scruss at sympatico dot ca
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 18 Sep 2002 20:51:43 +0100
- Subject: Re: [xsl] a nicer total sibling count than this
- Organization: Jeni Tennison Consulting Ltd
- References: <20020918193929.YLRF15511.tomts7-srv.bellnexxia.net@[209.226.175.22]>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Stewart,
> To my surprise and delight, the following worked, producing heavy
> def numbers with a following non-break space:
>
> <xsl:template match="def">
> <xsl:if test="(count(preceding-sibling::def) +
> count(following-sibling::def)) >= 1">
> <xsl:element name="strong">
> <xsl:number/>
> <xsl:text> </xsl:text>
> </xsl:element>
> </xsl:if>
> <xsl:apply-templates/>
> </xsl:template>
>
> Is there a prettier/more efficient way of doing the same thing
> without resorting to frankly ugly
> '(count(preceding-sibling::def)+count(following-sibling::def))'?
Since you don't actually need to know *how many* there are, just
whether there are any siblings of the current def or not, you could
use:
<xsl:if test="preceding-sibling::def or following-sibling::def">
...
</xsl:if>
or you could see if the def element's parent has more than one def
child:
<xsl:if test="../def[2]">
...
</xsl:if>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list