Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old October 29th, 2008, 06:29 PM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default not able to print out the child nodes

<test title="Home" link="4" >
<test title="about us" link="about" />
<test title="history" link="history" />
<test title="info" link="info" >
     <test title="press" link="press" />
     <test title="news" link="news" />
</test>
</test>




        [list]
        <xsl:for-each select="/test[@title='Home']/test">
        <li><xsl:value-of select@title"/></li>
    </xsl:for-each>
    </ul>
currently when I try to print the child node of Home I get about us history and info but I also want to print the child of any of the history, info or about us if it exists. The output of that I am looking for should give me [list]
    <li>about us</li>
    <li>history</li>
    <li>info</li>
    [list]
        <li>press</li>
        <li>news</li>
    </ul>
</ul>

What do I need to add to get this output?
  #2 (permalink)  
Old October 29th, 2008, 09:57 PM
Authorized User
 
Join Date: Sep 2008
Location: , , Singapore.
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi,

This may help u ,there may be some other ways also

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            [list]
                <xsl:for-each select="/test[@title]/test">
                    <xsl:value-of select="@title"></xsl:value-of>
                    <br />
                    [list]
                        <xsl:for-each select="test[@title]">
                            <li>
                                <xsl:value-of select="@title" />
                            </li>
                        </xsl:for-each>
                    </ul>
                </xsl:for-each>
            </ul>
        </html>
    </xsl:template>
</xsl:stylesheet>


Raj
  #3 (permalink)  
Old October 29th, 2008, 11:44 PM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

try this:

<xsl:template match="/">
        [list]
            <xsl:for-each select="./test[@title='Home']/test">
                <li><xsl:value-of select="@title"></xsl:value-of></li>
                <xsl:if test="test">
                [list]
                    <xsl:for-each select="./test">
                        <li><xsl:value-of select="@title"></xsl:value-of></li>
                        </xsl:for-each>
                </ul>
                    </xsl:if>
                    </xsl:for-each>
        </ul>

    </xsl:template>

------
Rummy
  #4 (permalink)  
Old October 30th, 2008, 07:33 AM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thank you so much it worked.


  #5 (permalink)  
Old October 30th, 2008, 08:40 AM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

one more question provided title="news" how do I traverse back so it prints

Home
info
news

  #6 (permalink)  
Old October 30th, 2008, 08:58 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>one more question provided title="news" how do I traverse back so it prints

Use the ancestor axis

<xsl:for-each select="ancestor-or-self::test">
  <xsl:sort select="position()" order="descending" data-type="numeric"/>
  <xsl:value-of select="@title"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
  #7 (permalink)  
Old October 30th, 2008, 10:06 AM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default

ok im trying

<xsl:for-each select="ancestor-or-self::test">
  <xsl:sort select="position()" order="descending" data-type="number"/>
  <xsl:value-of select="@title"/>
</xsl:for-each>

but nothing is displayed.

  #8 (permalink)  
Old October 30th, 2008, 10:33 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>ok im trying ... but nothing is displayed.

Then you've put the code in the wrong place.


Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the size of the child nodes. eruditionist XSLT 2 November 7th, 2008 11:59 AM
not able to print child nodes upto 2 level eruditionist XSLT 3 October 30th, 2008 01:10 PM
Retrieveal of child nodes.... nathilson21 Classic ASP XML 0 May 7th, 2007 04:54 AM
Trying to group child nodes aalbetski XSLT 3 November 18th, 2006 01:29 PM
counting child nodes Tomi XSLT 1 September 6th, 2006 03:26 AM





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