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 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>
 
Old May 9th, 2009, 08:39 AM
Friend of Wrox
 
Join Date: Nov 2007
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
 
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..
 
Old May 9th, 2009, 10:42 AM
Friend of Wrox
 
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.
 
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...
 
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..
 
Old May 9th, 2009, 11:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
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





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





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