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 | 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 May 9th, 2009, 08:26 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting the first child

Hi guys,

I need to get the first <para> child is <italic>, please give me the code xslt 2.0 samples.

Code:
<para>
<italic>Takagi</italic> dfsflksdfsdfjsd<bold>dfhsfh sd</bold>
</para>
<para>jhghjgjgjgg <bold>kgkgkg</bold> jgjhg hjg <italic>fgffgg</italic>fgdfhdgh</para>
Reply With Quote
  #2 (permalink)  
Old May 9th, 2009, 08:39 AM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

XPath to select the first 'italic' child element of the context node is simply 'italic[1]' so you would use
Code:
<xsl:template match="para">
  <xsl:value-of select="italic[1]"/>
</xsl:template>
to output the string value of the first 'italic' child element.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #3 (permalink)  
Old May 9th, 2009, 08:45 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi martin,

your code is working for both <Para> tag child first element is <italic> but, I need to get the first para tag italic only, not to select the second para/italic.


<para>
<italic>Takagi</italic> dfsflksdfsdfjsd<bold>dfhsfh sd</bold>
</para>

<para>jhghjgjgjgg <bold>kgkgkg</bold> jgjhg hjg <italic>fgffgg</italic>fgdfhdgh</para>

Last edited by Nagaraj; May 9th, 2009 at 08:49 AM..
Reply With Quote
  #4 (permalink)  
Old May 9th, 2009, 10:42 AM
Friend of Wrox
Points: 533, Level: 8
Points: 533, Level: 8 Points: 533, Level: 8 Points: 533, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

Code:
<xsl:value-of select="para[1]/italic[1]" />
Cheers, John Bampton.
Reply With Quote
  #5 (permalink)  
Old May 9th, 2009, 10:56 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi guys,

Sorry for missed out the details mentioned below,

In my task is need to select the parent element <para> having the first child as <italic> only to select else skip.

I think it's a clear detail for all...
Reply With Quote
  #6 (permalink)  
Old May 9th, 2009, 11:28 AM
Registered User
 
Join Date: May 2009
Posts: 3
Thanks: 3
Thanked 0 Times in 0 Posts
Default Use this

The following will do
Code:
   <xsl:template match="para[*[1][local-name()='italic']][1]">
if what you are asking for is the first para whose first child element is italic.

Last edited by keith h nicholsen; May 9th, 2009 at 04:02 PM..
Reply With Quote
  #7 (permalink)  
Old May 9th, 2009, 11:40 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

>I think it's a clear detail for all...

I'm sorry, you've now given three descriptions of your problem, all of them different, and none of them clear at all.

One of the problems is context: it's not clear where you are starting from. Another problem is that English is clearly not your first language (I can only guess what you mean by "only to select else skip").

It might be useful to describe the problem in terms of a complete transformation: show a complete input, and your complete required output, and your complete attempt at a stylesheet, and we'll then tell you where it's wrong.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #8 (permalink)  
Old May 11th, 2009, 03:57 AM
Authorized User
 
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much keith h nicholsen, this is exactly i want!!!!!!


Hi mhkay,

Yes mhkay. You clearly understand me i.e. English is not my first language...

Anyway this forum help me a lots, first I thank to all... for supporting me and guiding..

Thanks,
Nagaraj
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
checking for a child? gabster XSLT 2 March 7th, 2007 02:18 PM
Child Help. lafilip XSLT 6 November 20th, 2006 06:53 PM
Opening MDI Child on Button Click of MDI Child Sachin Shinde Visual Studio 2005 0 June 8th, 2006 05:05 AM
child table miguel.ossa C# 2 August 23rd, 2004 08:09 AM
MDI Child sidneyfuerte VB How-To 4 July 18th, 2004 08:11 PM



All times are GMT -4. The time now is 02:28 PM.


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