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 October 2nd, 2008, 04:38 AM
Authorized User
 
Join Date: Sep 2008
Location: , , Singapore.
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default selection based on conditions

Hi,
xml:..........

<catalog>
    <cd>
        <title def="2" >Empire1 </title>
        <title def="2" >Empire2 </title>
        <title def="2" >Empire3 </title>
        <title def="2">
            <run>raj1</run>
        </title>
        <title def="2">
            <run>raj2</run>
        </title>
        <title def="2">
            <run>raj3</run>
        </title>
    </cd>
</catalog>

when i require to select the values which are inside run tag alone i used this xsl statement to get the output

<xsl:for-each select="catalog/cd/title[@def='2']">
<xsl:value-of select="./run"/>
</xsl:for-each>



the below one gives me all the values which are in <title def="2" > tags along with the values of child tag run

<xsl:for-each select="catalog/cd/title[@def='2']">
<xsl:value-of select="."/>
</xsl:for-each>

how can i get the values from <title def="2" > tag ommiting the run tag.

i hav used the conditions like

<xsl:if test="string-length(normalize-space(catalog/cd/title[@def='2']/run)) &gt; 0">

to show the values under run tag alone..

but how to get the values other than run tag....


Thanks
Raj..



Reply With Quote
  #2 (permalink)  
Old October 2nd, 2008, 04:53 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The simplest way would be to select the text node in <title>, like so:

<xsl:value-of select="text()"/>

You will probably find that this outputs more whitespace than you might have expected, but should get you closer to what you want.

A slightly different version that only outputs text nodes with something in them would look like this:

<xsl:value-of select="text()[normalize-space(.)!='']"/>

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #3 (permalink)  
Old October 2nd, 2008, 05: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

It would really help if you could learn the correct terminology (using the wrong terminology suggests that you haven't grasped the basic concepts). When you talk about "omitting the run tag", I strongly suspect that you mean "omitting the run element". Remember that an element has two tags, a start tag and an end tag. I suspect you want to omit the content between the tags (that is, the children of the element node) as well as the tags themselves.

Your code

<xsl:for-each select="catalog/cd/title[@def='2']">
<xsl:value-of select="."/>
</xsl:for-each>

will output the string value of the element - that is, its contained text - without any tags. That's what you asked for, but I suspect it's not what you want.

I'm not really sure what you do want, but if you only want the content of title elements that do not have a run child element, it would be

<xsl:for-each select="catalog/cd/title[@def='2'][not(run)]">
<xsl:value-of select="."/>
</xsl:for-each>

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old October 2nd, 2008, 08:06 PM
Authorized User
 
Join Date: Sep 2008
Location: , , Singapore.
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi kay,

yes u were correct i require title elements that do not have a run child element.
i require only for these three

 <title def="2" >Empire1 </title>
 <title def="2" >Empire2 </title>
 <title def="2" >Empire3 </title>


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
Fill DataGrid based on the selection in combobox drani C# 12 October 11th, 2007 05:41 PM
Changing combobox based on selection iamme Visual Basic 2005 Basics 0 January 31st, 2007 09:04 PM
validate zipcode based on country selection. debjanib ASP.NET 1.0 and 1.1 Professional 5 August 14th, 2006 04:35 PM
Query based on combo box selection help Elain Access 1 January 3rd, 2006 11:33 PM
Getting data based on field selection Trojan_uk Classic ASP Basics 1 December 9th, 2003 10:47 AM



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


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