Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 June 27th, 2008, 02:33 PM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default To Select a specific nodes from XML

Hello, im new working with XSL and had a question, Im having a XML shown below.
<main>
<content>
<name>A</name>
<dept>X</dept>
</content>
<content>
<name>B</name>
<dept>Y</dept>
</content>
<content>
<name>C</name>
<dept>X</dept>
</content>
<content>
<name>D</name>
<dept>Y</dept>
</content>
</main>

i want display only names who are in dept Y.
Any help from any would be gr8.
Thanks in advance

Reply With Quote
  #2 (permalink)  
Old June 27th, 2008, 02:48 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

/main/content[dept='Y']/name

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old June 27th, 2008, 03:11 PM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hello Michael Kay,
Thanks for your help, actually the exact XMl looks like this
<main>
    <content>
        <test>ab</test>
        <content2>
            <name>A</name>
            <dept>X</dept>
        </content2>
    </content>
    <content>
        <test>cd</test>
        <content2>
            <name>B</name>
            <dept>Y</dept>
        </content2>
    </content>
    <content>
        <test>ef</test>
        <content2>
            <name>C</name>
            <dept>X</dept>
        </content2>
    </content>
    <content>
        <test>gh</test>
        <content2>
            <name>D</name>
            <dept>Y</dept>
        </content2>
    </content>
</main>

I would like to Display
Test Name Dept
cd B Y
gh D Y

Presently im using XSL
<table>
    <tr>
        <td>Test</td>
        <td>Name</td>
        <td>Dept</td>
    </tr>
    <xsl:for-each select="main/content">
    <tr>
        <td><xsl:value-of select="test"/></td>
        <td><xsl:value-of select="content2/name"/></td>
        <td><xsl:value-of select="content2/dept"/></td>
    </tr>
    </xsl:for-each>
</table>


which prints all the nodes, as i have told i need to print nodes which dept is Y
Thanks

Reply With Quote
  #4 (permalink)  
Old June 27th, 2008, 03:32 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 Posts
Default

What part of my answer didn't you understand? It really ought to be possible to adapt the answer to a slightly different problem - if you can't do that then there's not much point giving you the answer, or you'll be back here every time the problem changes slightly.

Change the for-each to

<xsl:for-each select="main/content[content2/dept='Y']">


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old June 27th, 2008, 03:39 PM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Really thanks for the Help, as im new too XSLT(just started at my work few days back), i asked you again for the help.

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
Processing specific Nodes Krippers XSLT 3 November 6th, 2008 05:38 AM
Select nodes randomly carlosaml XSLT 3 October 17th, 2007 10:18 AM
How to select these nodes? hustsay23 XSLT 1 September 7th, 2006 04:15 AM
Help accessing specific nodes jshl_wiz Javascript 2 June 29th, 2005 09:45 PM
Help: Select every node except these nodes arcuza XSLT 8 May 25th, 2005 08:07 AM



All times are GMT -4. The time now is 09:48 PM.


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