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 June 27th, 2008, 02:33 PM
Registered User
 
Join Date: Jun 2008
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

 
Old June 27th, 2008, 02:48 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old June 27th, 2008, 03:11 PM
Registered User
 
Join Date: Jun 2008
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

 
Old June 27th, 2008, 03:32 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old June 27th, 2008, 03:39 PM
Registered User
 
Join Date: Jun 2008
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.






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





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