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 | 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 December 31st, 2008, 05:44 PM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default having issue printing child values by comparing parents value

Here is my XML
<root>
<value>
<item name="key">
<value>Test</value>
</item>
<item name="label">
<value>&lt;b&gt;Test&lt;/b&gt;</value>
</item>
<item name="foldername">
<value>Test</value>
</item>
<value>
<item name="key">
<value>Test1.1</value>
</item>
<item name="label">
<value>Test 1.1</value>
</item>
<item name="foldername">
<value/>
</item>
</value>
<value>
<item name="key">
<value>Test1.2</value>
</item>
<item name="label">
<value>Test 1.2</value>
</item>
<item name="foldername">
<value/>
</item>
</value>
</item>
<item name="key">
<value>Sample</value>
</item>
<item name="label">
<value>&lt;b&gt;Sample&lt;/b&gt;</value>
</item>
<item name="foldername">
<value>Sample</value>
</item>
</value>
</root>



=============================================
I am trying to print just this as the output

PARENT key=Test label=Test foldername=Test
CHILD Key=Test1.1 label=Test 1.1 foldername=
CHILD Key=Test1.2 label=Test 1.2 foldername=

I know that in order to get the value I need to use
<xsl:value-of select="//item/value"/>
What I dont know is how do I print out the output thats needed by providing just Test as my item name key.
Reply With Quote
  #2 (permalink)  
Old December 31st, 2008, 06:05 PM
Authorized User
 
Join Date: Dec 2008
Location: London
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

Code:
<xsl:value-of select="//item/@name"/>
Reply With Quote
  #3 (permalink)  
Old January 1st, 2009, 06:57 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

It's very hard to discern the structure of your input as there is no indentation. I tried pasting it into an XML editor to get it indented, and it seems that it isn't even well-formed, which makes it even harder to see the intended structure! Also it doesn't help that you have used "Test" as the value of many different fields, which makes it difficult to see which parts of your output are supposed to come from which parts of your input.

Escaping the nested markup within the <value> elements isn't going to make your life easier either.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #4 (permalink)  
Old January 5th, 2009, 03:37 PM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 56
Thanks: 0
Thanked 1 Time in 1 Post
Default Here is the correct XML

<?xml version="1.0"?>
<root>
<value>
<item name="key">
<value>News</value>
</item>
<item name="label">
<value>&lt;b&gt;News&lt;/b&gt;</value>
</item>
<item name="foldername">
<value>news</value>
</item>
<value>
<item name="key">
<value>Sportsnews</value>
</item>
<item name="label">
<value>Sports News</value>
</item>
<item name="foldername">
<value/>
</item>
</value>
<value>
<item name="key">
<value>FinancialNews</value>
</item>
<item name="label">
<value>Financial News</value>
</item>
<item name="foldername">
<value/>
</item>
</value>
<item name="key">
<value>Classifieds</value>
</item>
<item name="label">
<value>&lt;b&gt;classifieds&lt;/b&gt;</value>
</item>
<item name="foldername">
<value>sell</value>
</item>
</value>
</root>



I need just the News and its children values to be printed out for example.
Parent key value = News
children key value = Sportsnews
children key value = FinancialNews

I hope this makes sense.
Reply With Quote
The Following User Says Thank You to eruditionist For This Useful Post:
mrame (January 7th, 2009)
  #5 (permalink)  
Old January 7th, 2009, 02:34 AM
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 the below code. This is hard-coded for two value elements as per the input. There can be better solution.
Code:
<xsl:template match="root">
<xsl:apply-templates select="value" mode="value"></xsl:apply-templates>
</xsl:template>

<xsl:template match="value" mode="value">
<xsl:apply-templates select="item" mode="item"></xsl:apply-templates>
</xsl:template>

<xsl:template match="item" mode="item">
<xsl:if test="value = 'News'">
Parent key value = <xsl:value-of select="value"></xsl:value-of>
Children key value = <xsl:value-of select="../value[1]/item[@name = 'key']/value"></xsl:value-of>
Children key value = <xsl:value-of select="../value[2]/item[@name = 'key']/value"></xsl:value-of>
</xsl:if>
</xsl:template>

__________________
Rummy
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
Comparing Two values from same table MArgente BOOK: Beginning SQL 3 December 11th, 2009 07:35 AM
Comparing values between different MSHFlexGrid davekrunal46 VB How-To 0 November 28th, 2005 07:41 AM
Comparing values between different MSHFlexGrid davekrunal46 VB Databases Basics 0 November 28th, 2005 07:39 AM
Comparing values between different MSHFlexGrid davekrunal46 Beginning VB 6 0 November 28th, 2005 07:38 AM
Comparing Dates Issue tdaustin Classic ASP Basics 2 June 2nd, 2004 06:30 PM



All times are GMT -4. The time now is 03:38 PM.


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