[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Position() question

Subject: Re: Position() question
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 01 Sep 2000 19:09:18 +0100
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.