xsl-list
[Top] [All Lists]

[xsl] Trouble selecting nodes form a nodeset

2007-06-07 15:04:11
I have a variable that I'm creating as a node list and attempting to
select nodes from that list.  I'm having trouble understanding why the
this won't work.  Applying templates to the entire node list and then
matching seems to work okay, but not selecting specific nodes from the
list.  Source & XSLT are below...

The output from running this transform is the following:

member = member one
  element = element one dot one
  element = element one dot two
member = member two
  element = element two dot one
  element = element two dot two
ELEMENT: element one dot one
ELEMENT: element one dot two
ELEMENT: element two dot one
ELEMENT: element two dot two

I would expect to see the output from the template match of
<xsl:template match="member" mode="alt"> (below) but don't find it.

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>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>