Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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?
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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.


Reply With Quote
  #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

Reply With Quote
  #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
Reply With Quote
  #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.

Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:15 PM.


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