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

Selecting node at a certain position from a nodeset

Subject: Selecting node at a certain position from a nodeset
From: Marco Guazzone <sguazt@xxxxxxxxxxx>
Date: Wed, 22 Jan 2003 14:06:12 +0100 (CET)
xsl select node
Hi,
  I want to select node at position $pos (e.g. $pos = number('1')) from a
  nodeset; here below are the XML-XSL sheets with which I have to work.
  Inside template "/doc" there are three "apply-templates" instructions:
  * the 1st selects all nodes satisfying the xpath conditions (this is
    showed only for debugging purpose)
  * the 2nd should select node at position $pos; instead it doesn't work!!
    Why??!?!?!!?
  * the 3rd select node at position $pos and works!!!
  So why doesn't the 2nd one work?
  Anyone has a better solution?
Thanks in advance!

XML:
<?xml version="1.0"?>

<doc>
        <sections>
                <section id="1" group="1">
                        <item id="1">item1-section1</item>
                        <item id="2">item2-section1</item>
                </section>
                <section id="2" group="2">
                        <item id="1">item1-section2</item>
                        <item id="2">item2-section2</item>
                </section>
                <section id="3" group="3">
                        <item id="1">item1-section3</item>
                        <item id="2">item2-section3</item>
                </section>
                <section id="4" group="1">
                        <item id="1">item1-section4</item>
                        <item id="2">item2-section4</item>
                </section>
                <section id="5" group="1">
                        <item id="1">item1-section5</item>
                        <item id="2">item2-section5</item>
                </section>
        </sections>
</doc>
 
XSL:
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:exsl="http://exslt.org/common"
>

<xsl:variable name="sections" select="/doc/sections"/>
<xsl:variable name="pos" select="1"/>

<xsl:template match="/doc">
        <xsl:apply-templates
select="$sections/section[@group=1]/item[@id=1]"/>
        <xsl:text>&#x0A;</xsl:text>
        <xsl:apply-templates
select="$sections/section[@group=1]/item[@id=1][$pos]"/>
        <xsl:text>&#x0A;</xsl:text>
        <xsl:apply-templates
select="exsl:node-set($sections/section[@group=1]/item[@id=1])[$pos]"/>
</xsl:template>

<xsl:template match="item">
        <xsl:apply-templates/>
        <xsl:text>&#x20;</xsl:text>
</xsl:template>

</xsl:stylesheet>

-------------------------------
Marco Guazzone
Software Engineer
Kerbero S.r.L. - Gruppo TC
Viale Forlanini, 36
Garbagnate M.se (MI)
20024 - Italy
mail: marco.guazzone@xxxxxxxxxxx
www: http://www.kerbero.com
Tel. +39 02 99514.247
Fax. +39 02 99514.399
--------------------------------


 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.