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

Count previous-siblings w/same attribute value up to

Subject: Count previous-siblings w/same attribute value up to attribute value - 1 possible?
From: "Murray McDonald" <m.mcdonald@xxxxxxxxx>
Date: Mon, 12 Dec 2011 22:11:04 -0500
 Count previous-siblings w/same attribute value up to
I would think Ken's grouping solution is the way to go - just to demonstrate
there is usually a number of ways one can solve a problem using XSLT ...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:fn="http://www.w3.org/2005/xpath-functions">
	
<xsl:output method="text"/>


	
<xsl:template match="item">
	<xsl:variable name="thisLevel" select="@level"/>
	<xsl:variable name="prevLevel"
select="string(number($thisLevel)-1)"/>
	<xsl:variable name="closest_prev_level"
select="preceding-sibling::item[@level eq $prevLevel][1]" as="node()*"/>
	<xsl:variable name="formats" select="('I.', 'A.', '1.')"
as="xs:string*"/>
	<xsl:variable name="format_for_this_level"
select="$formats[number($thisLevel)]"/>

    <xsl:variable name="designator" as="xs:string">
		<xsl:number count="item[@level eq $thisLevel]" from="item[.
is $closest_prev_level]" level="any" format="{$format_for_this_level}"/>
    </xsl:variable>

	
	<xsl:text>Item with numDisplay attribute &quot;</xsl:text>
	<xsl:apply-templates select="@numDisplay"/>
	<xsl:text>&quot;, designator is </xsl:text>
	<xsl:value-of select="$designator"/>
	<xsl:text>&#10;</xsl:text>
</xsl:template>	
</xsl:stylesheet>


Item with numDisplay attribute "I.", designator is I.
Item with numDisplay attribute "II.", designator is II.
Item with numDisplay attribute "A.", designator is A.
Item with numDisplay attribute "B.", designator is B.
Item with numDisplay attribute "C.", designator is C.
Item with numDisplay attribute "III.", designator is III.
Item with numDisplay attribute "A.", designator is A.
Item with numDisplay attribute "1.", designator is 1.
Item with numDisplay attribute "2.", designator is 2.
Item with numDisplay attribute "3.", designator is 3.
Item with numDisplay attribute "4.", designator is 4.
Item with numDisplay attribute "B.", designator is B.
Item with numDisplay attribute "1.", designator is 1.
Item with numDisplay attribute "2.", designator is 2.
Item with numDisplay attribute "3.", designator is 3.
Item with numDisplay attribute "C.", designator is C.

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.