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

RE: Trouble selecting nodes form a nodeset

Subject: RE: Trouble selecting nodes form a nodeset
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 7 Jun 2007 23:39:48 +0100
RE:  Trouble selecting nodes form a nodeset
> I would expect to see the output from the template match of 
> <xsl:template match="member" mode="alt"> (below) but don't find it.

$nodelist/member selects the member children of all elements in $nodelist.
Some of the nodes in $nodelist are member elements, but none of them has a
child named member.

You want $nodelist[self::member] (or $nodelist/self::member if you prefer)

Michael Kay
http://www.saxonica.com/

> 
> Any ideas?  Thanks...
> --jah
> 
> == test.xml ==
> <group>
>   <member name="member one">
>     <element name="element one dot one" />
>     <element name="element one dot two" />
>   </member>
>   <member name="member two">
>     <element name="element two dot one" />
>     <element name="element two dot two" />
>   </member>
> </group>
> 
> == test.xsl ==
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:output method="text" />
> 
>   
> <!--===============================================================-->
>   <xsl:template match="/">
>     <xsl:variable name="nodelist" select="group/member | 
> group/member/element " />
>     <xsl:apply-templates select="$nodelist" />
> 
>     <xsl:apply-templates select="$nodelist/member" mode="alt" />
>     <xsl:apply-templates select="$nodelist/element" mode="alt" />
>   </xsl:template>
> 
>   
> <!--===============================================================-->
>   <xsl:template match="member">
>     <xsl:value-of select="name()" />
>     <xsl:text> = </xsl:text>
>     <xsl:value-of select="@name" />
>     <xsl:text>
> </xsl:text>
>   </xsl:template>
> 
>   
> <!--===============================================================-->
>   <xsl:template match="element">
>     <xsl:text>  </xsl:text>
>     <xsl:value-of select="name()" />
>     <xsl:text> = </xsl:text>
>     <xsl:value-of select="@name" />
>     <xsl:text>
> </xsl:text>
>   </xsl:template>
> 
>   
> <!--===============================================================-->
>   <xsl:template match="member" mode="alt">
>     <xsl:text>MEMBER: </xsl:text>
>     <xsl:value-of select="@name" />
>     <xsl:text>
> </xsl:text>
>   </xsl:template>
> 
>   
> <!--===============================================================-->
>   <xsl:template match="element" mode="alt">
>     <xsl:text>ELEMENT: </xsl:text>
>     <xsl:value-of select="@name" />
>     <xsl:text>
> </xsl:text>
>   </xsl:template>
> 
> </xsl:stylesheet>

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.