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

counting with position()

Subject: counting with position()
From: a kusa <akusa8@xxxxxxxxx>
Date: Tue, 5 Jan 2010 11:26:13 -0600
 counting with position()
Hi

I am trying to count nodes after a certain node and am having
difficulties with it.
Here is my snippet:

<level1>
<item>Sample</item>
         <level2>
<item>Sample</item>
<product>sample prod1</product>
<product>sample prod2</product>
<product>sample prod3</product>
               <level3>
                  <item>Sample</item>
                  <item>Sample</item>
                </level3>
          </level2>
<level1>

So I am trying to count all 'product elements after <item> in the
template level2.

Here is a part of my xslt.

<xsl:template match="level2">

<xsl:if test="following-sibling::*[1][self::product[preceding-sibling::*[1][self::item]
and following-sibling::*[self::product[(position()=last()) and
not(string(following-sibling::*[1]))]]]]">
					<xsl:variable name="count"
select="count(./following-sibling::product[position()!=last()])"/>
					<xsl:if test="$count>= 1">
						<xsl:apply-templates
select="./following-sibling::product[position() &lt; $count]"/>
					</xsl:if>
				</xsl:if>

</xsl:template>


I am trying to find out if there is more than one 'product' after
<item> and  if that occurs at the end of <item> just before <level3>
starts. The transformation is a lot more complicated than just this,
since these are all nested levels and this kind of structure can occur
in an another <level3> element down the node tree.
After I check that, I count the product elements and transform them.

But when I use ./following-sibling::product[position() &lt; $count],
it only shows 1 product element.

How do I count all the product elements and display until the last one?

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.