|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Position() question
Matthew,
>, but only if I strip whitespace so that position() doesn't pick it up
>whitespace nodes.
>How can I preserve whitespace and still output the correct label number,
>without resorting to: <xsl:value-of select="count(preceding-sibling::text +
>1)" /> ?
position() gives you the index of the current node within the current node
list. So one way to do it is to make the current node list be the list
that you need in order to give the position() that you want.
You want to number the 'text' elements with respect to each other. With
position(), you can do this by making sure the current node list only
contains 'text' elements. In other words, by selecting only those elements
for processing:
<xsl:template match="head">
<head>
<xsl:apply-templates select="text" />
</head>
</xsl:template>
<xsl:template match="text">
<item>
<label><xsl:value-of select="position()" /></label>
<text><xsl:value-of select="." /></text>
</item>
</xsl:template>
Another thing that you can do is to use xsl:number, which is specially
designed to give you numbering in your output. Probably a more elegant and
transparent solution than using position() is to use xsl:number. Without
any attributes, it will give you the index of the 'text' element amongst
its 'text' element siblings:
<xsl:template match="text">
<item>
<label><xsl:number /></label>
<text><xsl:value-of select="." /></text>
</item>
</xsl:template>
I hope that this helps,
Jeni
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








