This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: a nicer total sibling count than this
- From: "Macaulay,Malcolm (US)" <Malcolm dot Macaulay2 at cnare dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 18 Sep 2002 15:05:44 -0500
- Subject: RE: [xsl] a nicer total sibling count than this
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Stewart,
You don't need all the counting stuff. If I understand you correctly, the test is simply: "is there a preceding def element?". If so then there must be 2 or more defs for the word. I.e. the following template should work just as well:
<xsl:template match="def">
<xsl:if test="preceding-sibling::def">
<xsl:element name="strong">
<xsl:number/>
<xsl:text> </xsl:text>
</xsl:element>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
Hope that helps.
cheers
Malcolm
-----Original Message-----
From: scruss@sympatico.ca [mailto:scruss@sympatico.ca]
Sent: Wednesday, September 18, 2002 2:39 PM
To: xsl-list@lists.mulberrytech.com
Subject: [xsl] a nicer total sibling count than this
I'm working with a dictionary marked up in XML. Conventionally, one numbers definitions (def elements here) only if there are two or more definitions for the given part of speech.
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))'?
thanks,
Stewart
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list