|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Unable to get text() of node
Hi Liron,
I think you need
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<tree>
<xsl:for-each select="tree/child/childname">
<childText>
<xsl:value-of select="../text()[2]"/>
</childText>
</xsl:for-each>
</tree>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
On 1/21/06, Liron <magilam@xxxxxxxxxxxxxxxx> wrote:
> Hello,
>
> I'm a very new member (just joined) to this mailing list and to xsl in
> general so I hope I can get some help here. Please be patient :)
>
> I have the following xml content:
>
> <tree>
> <child>First Child</child>
> <child>
> <childname>SecondChild</childname>
> Second Child
> </child>
> <child>
> <childname>ThirdChild</childname>
> Third Child
> </child>
> </tree>
>
> I want to create a xsl that will return a tree with just the text of each
> <child> node without the text of any descendents. I tried using this xsl:
>
> <?xml version='1.0' encoding='utf-8'?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="html"/>
> <xsl:template match="/">
> <tree>
> <xsl:for-each select="tree/child/childname">
> <childText>
> <xsl:value-of select="../text()"/>
> </childText>
> </xsl:for-each>
> </tree>
> </xsl:template>
> </xsl:stylesheet>
>
> I'm selecting only nodes that have a childname child (not interested in
> nodes that don't)
> and I'm trying to get the text() of the parent. The output is in fact 2
> nodes as expected but they're empty.
> If I choose "tree/child" in the loop and use "text()" as value of I get 3
> nodes back where only the first has a value which leads me to believe that
> the text in the other
> children is not really considered as text. What's the right syntax for the
> results I'm expecting?
> Just to make things clear - I'm expecting this output:
>
> <tree>
> <childText>Second Child</childText>
> <childText><Third Child</childText>
> </tree>
>
>
> Thank you very much
> Liron
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








