 |
| 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
|
|
|
|

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

May 9th, 2009, 08:39 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

May 9th, 2009, 08:45 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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..
|
|

May 9th, 2009, 10:42 AM
|
|
Friend of Wrox
|
|
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
|
|
Code:
<xsl:value-of select="para[1]/italic[1]" />
Cheers, John Bampton.
|
|

May 9th, 2009, 10:56 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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...
|
|

May 9th, 2009, 11:28 AM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 3
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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..
|
|

May 9th, 2009, 11:40 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>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
|
|

May 11th, 2009, 03:57 AM
|
|
Authorized User
|
|
Join Date: Apr 2009
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |