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 January 28th, 2011, 09:29 AM
Registered User
 
Join Date: Jan 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Only the first node comments

Hi

I need to get the first name "comment".

<unit language="C++" dir="" filename="XXX.h"><comment>//<text> $Id:$</text></comment>
<comment>//<text>*******************</text></comment>
<comment>//<text/></comment>
<comment>//<text> PROYECTO: XXX</text></comment>
<comment>//<text/></comment>
<comment>//<text> NOMBRE MODULO: XXX</text></comment>
<comment>//<text> PREFIJO: XXX</text></comment>
<comment>//<text/></comment>
<comment>//<text> AUTOR/ES: XXX</text></comment>
<comment>//<text/></comment>
<comment>//<text> DESCRIPCION DEL MODULO:</text></comment>
<comment>//<text> Clase Linea</text></comment>
<comment>//<text/></comment>
<comment>//<text>***************</text></comment>

<ifndef>#<directive>ifndef</directive> <name>_XXX_H</name></ifndef>
<define>#<directive>define</directive> <name>_XXX_H</name></define>
<comment>//</comment>
....
</unit>

I have using template and recursive:

<xsl:template match="unit">
<xsl:value-of select="comment"/>
<xsl:apply-templates select="descendant::*[position()= 1 and
name()='comment']" mode="after" />
</xsl:template>

<xsl:template match="comment" mode="after">
<xsl:apply-templates select="following-sibling::*[position()=1 and
name()='comment']" mode="after"/>
<pre class="comment"> <xsl:value-of select="text"/> </pre>
</xsl:template>

But the out look like that, the first name shows at the end.
*******************************
Clase Linea
DESCRIPCION DEL MODULO:
AUTOR/ES: XXX
PREFIJO: XXX
NOMBRE MODULO: XXX
PROYECTO: XXX
*******************************
$Id:$

Somebody can help me. I am working with this, but i still do not work well.

Saludos.
 
Old January 28th, 2011, 10:37 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I'm not entirely sure what your problem is or how you are getting the output you are. It may depend on which XSLT processor you are using.

But I think there are a number of things you have got wrong anyway.

The first is that depending on which version of XSLT you are using <xsl:value-of select="comment"> will write out the textual value of all child comment elements, or just the first, so doing <xsl:value-of select="comment[1]"/> would be more specific.

To select the 'next' comment element you can also do this: <xsl:apply-templates select="following-sibling::comment[1]"/>.

Also, because you have the <xsl:value-of select="text"/> after the <xsl:apply-templates> you are going to be outputting stuff in the reverse order.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old January 28th, 2011, 11:31 AM
Registered User
 
Join Date: Jan 2011
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Muchas gracias.

Saludos.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a node to an existing xml node list. codehelp C# 2008 aka C# 3.0 2 October 12th, 2009 07:41 AM
Displaying data as a Parent Node with Left Node and Right Node Manoj Bisht Visual Basic 2008 Professionals 0 April 2nd, 2009 02:34 AM
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
how to append child node after an node in XML + C# vishnu108mishra XML 5 November 13th, 2007 05:30 AM
Copying Source Node attributes to output node pvsat XSLT 2 November 3rd, 2005 09:46 AM





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