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 October 2nd, 2008, 04:38 AM
Authorized User
 
Join Date: Sep 2008
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..



 
Old October 2nd, 2008, 04:53 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old October 2nd, 2008, 05:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old October 2nd, 2008, 08:06 PM
Authorized User
 
Join Date: Sep 2008
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>







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





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