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 November 6th, 2007, 07:10 AM
Registered User
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to select only the parent tag and ignore the c

Hi,

My XML is in the following form

<Employee>Employee details
    <name>kumar</name>
    <country>india</country>
</Employee>

I want to select only the following data "Employee details" from the <Employee> tag, I don't want to select the child nodes in my XSLT. Does any one have the idea about how to select only the parent tag and ignore the child tag

Thanks & Regards,
Prem Rajesh Kumar.S

 
Old November 6th, 2007, 07:17 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's not a well designed XML document structure, and I should change it if possible, but you can extract the first text node of the Employee element by doing

<xsl:template match="Employee">
  <details>
    <xsl:value-of select="normalize-space(text()[1])"/>
  </details>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 6th, 2007, 11:24 AM
Registered User
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thx for ur suggestion, but its not working. this is my original XML

    <ENTRY>
    <MWORD ID="000000114">
    <WORD>abduction</WORD>
    <SYL>ab&dot;duc&dot;tion</SYL>
    <PHON>ab-duk&stress;shun</PHON>
    <DEF>the act of abducting; the state of being abducted.
       <FIGURE>
         <IMAGE TYPE="float" FILE="abduction(1)"/>
         <FIG.CAPTION>Abduction of the fingers.</FIG.CAPTION>
       </FIGURE>
        </DEF>
        </MWORD>
    </ENTRY>
like this it has lot of <ENTRY> tags...

In this XML i want to get the only text of <DEF> tag ("the act of abducting; the state of being abducted."), i don't want to get the results of sub tags of <DEF> tag. Please advise me.

Quote:
quote:Originally posted by Prem Rajesh Kumar
 Hi,

My XML is in the following form

<Employee>Employee details
    <name>kumar</name>
    <country>india</country>
</Employee>

I want to select only the following data "Employee details" from the <Employee> tag, I don't want to select the child nodes in my XSLT. Does any one have the idea about how to select only the parent tag and ignore the child tag

Thanks & Regards,
Prem Rajesh Kumar.S

 
Old November 6th, 2007, 12:53 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I need to know exactly what you did and exactly how it failed so that I can see what you did wrong.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Quest: How to select the second tag?! gnesland XSLT 4 November 28th, 2006 11:09 AM
get displayed name of the <select> tag nikeshkm HTML Code Clinic 1 October 20th, 2006 11:21 PM
can't read value from select tag using javascript kumar_kumar Javascript 2 February 9th, 2005 11:18 PM
Select parent node when any one child has key pparadesia XSLT 2 January 7th, 2005 11:29 AM
Dynamic Select Tag fs22 Javascript How-To 1 December 15th, 2004 08:32 PM





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