Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 5th, 2003, 07:33 PM
Registered User
 
Join Date: Sep 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default get all children nodes

I am trying to get the names of all chidren nodes, however I only get some of them. Please, help.

here is my sample XML file :

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="testtransform.xsl"?>
<Object>
       <Test>
        <Node>
            <case1>it </case1>
            <case2>works </case2>
        </Node>
    </Test>
    <Test>
        <Node>
            <case3>here</case3>
            <case4> we go</case4>
        </Node>
    </Test>
</Object>

Here is my XSL file:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="//Node">

<xsl:value-of select = "name(descendant::*)"/>

</xsl:template>
</xsl:stylesheet>

Here is the output:

case1case3

Question:
Why isn't XSL returning case2 and case 4 which are the other nodes in the XML file?

Thanks

 
Old November 6th, 2003, 02:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

First of all, change "//Node" to "Node" in the match attribute of the xsl:template.
Second, you didn't get "case2" and "case4" since the "name" function returns the element name of the first node in the argument node-set. You can use xsl:for-each to get all element names in the node set.

Regards,
Armen
 
Old November 6th, 2003, 01:07 PM
Registered User
 
Join Date: Sep 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Armen,
what should be the select expression in the xsl:for-each? When I use
xsl:for-each select="Node/*", nothing is returned in the output.
Thanks,



Quote:
quote:Originally posted by armmarti
 First of all, change "//Node" to "Node" in the match attribute of the xsl:template.
Second, you didn't get "case2" and "case4" since the "name" function returns the element name of the first node in the argument node-set. You can use xsl:for-each to get all element names in the node set.

Regards,
Armen
 
Old November 7th, 2003, 11:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Code:
<xsl:template match="Node">
  <xsl:for-each select="descendant::*">

     <xsl:value-of select="name()"/>
     <xsl:if test="position() != last()">,</xsl:if>
  </xsl:for-each>
</xsl:template>
Regards,
Armen
 
Old November 7th, 2003, 02:07 PM
Registered User
 
Join Date: Sep 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Armen,

Thank you. That worked.






Similar Threads
Thread Thread Starter Forum Replies Last Post
help with nodes/children bmmayer XML 0 July 13th, 2007 05:04 PM
having trouble with nodes/children bmmayer XSLT 3 July 13th, 2007 04:52 PM
MDI Children angelboy C# 2005 5 June 28th, 2007 06:08 AM
unique children detection rjonk XSLT 1 June 30th, 2006 11:20 PM
match only first level children sgruhier XSLT 1 February 22nd, 2005 05:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.