[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
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 "</xsl:text> <xsl:apply-templates select="@numDisplay"/> <xsl:text>", designator is </xsl:text> <xsl:value-of select="$designator"/> <xsl:text> </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.
|
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
|