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

Finding position of specific element node in nodeset c

Subject: [xsl] Finding position of specific element node in nodeset context
From: "Sean Healy" <shealy@xxxxxxxxxxxxx>
Date: Sat, 24 May 2003 23:30:43 -0600
xsl element position
How do I construct a variable such that it represents the position of a specific element node? Thatis, I‘d like to build an XPath expression that finds the relative position of the first “ChapterNumber” that the parser encounters when iterating over the last “frontBreak”.  
         
For example, here’s the XML:

<?xml version="1.0"?>
<book>
<section>
<p stylename="docTitle" <string >Lucky</string></p>
<p stylename="FrontMatter" <string>BY </string></p>
…
<p stylename="frontBreak" align="right" fontsize="24"></p>
<p stylename="docAuthor" <string> Joe Smith</string></p>
<p stylename="docTitle" <string >Lucky</string></p>
<p stylename="FrontMatter" <string>BY </string></p>
<--Here’s frontBreak[last()]-->
<p stylename="frontBreak" align="right" fontsize="24"></p>
<p stylename="docAuthor" <string> Joe Smith </string></p>
<p stylename="FrontMatter" <string>BY </string></p>
<!--Here’s ChapterNumber[1]-->
<p stylename="ChapterNumber" <string>1</string></p>
<p stylename=" somethingelse3" <string> text3</string></p>
<p stylename="ChapterNumber" <string>1</string></p>
<p stylename="somethingelse1" <string >text1</string></p>
<p stylename=" somethingelse3" <string> text3</string></p>
…
</section>
</book>

Here’s what my template looks like so far:

<xsl:template match="p[@stylename='frontBreak']">
<!—Note that I’ve hardcoded $chaptnum_limit, but I would like an Xpath expression to replace ‘3’.-->
<xsl:variable name="chaptnum_limit" select="3"/>
    <xsl:element name="div1">
         <xsl:attribute name="n"><xsl:value-of select="position()"/></xsl:attribute> 
         <xsl:attribute name="type">front</xsl:attribute> 
             <xsl:element name="head"><xsl:value-of select="node()"/>
    </xsl:element>
   <xsl:for-each select=".">
      <xsl:variable name="frt_br" select="generate-id()"/>
         <xsl:for-each select="following-sibling::p[@stylename != 'frontBreak']
            [generate-id(preceding-sibling::p[@stylename = 'frontBreak'][1]) = $frt_br]">
                 
                <xsl:if test="position() &lt; $chaptnum_limit">
                      <xsl:value-of select="."/>
                </xsl:if>
           
       </xsl:for-each>
   </xsl:for-each>
   </xsl:element>
 </xsl:template>

I am not sure if this is the right approach (<xsl:if test="position() &lt; $chaptnum_limit">), but it was all I could come up with to keep this template from providing the values of all <p>’s until EOF when processing frontBreak[last()]. Thank you for your help in advance. –shealy


 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.