[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Unable to get text() of node

Subject: Re: Unable to get text() of node
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Sat, 21 Jan 2006 19:59:45 +0000
Re:  Unable to get text() of node
On 1/21/06, Liron <magilam@xxxxxxxxxxxxxxxx> wrote:
> Hi Hugh,
>
> Thank you very much for your reply.
> Unfortunetaly "parent::child/text()" didn't work for me and returned empty
> nodes. The only solution offered to me that worked so far is "text()[2]",
> but like you said, if the text is located before the childname node or in
> any other position than the second one, it won't work...
> I'm using libxsl to do all the xsl processing


You can use the following stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <tree>
    <xsl:apply-templates select="tree/child[childname]"/>
  </tree>
</xsl:template>

<xsl:template match="child">
  <childText>
    <xsl:apply-templates/>
  </childText>
</xsl:template>

<xsl:template match="childname"/>

</xsl:stylesheet>

But I would suggest that you source XML structure should be changed
because when you have:

<node>
   <child/>
   Some text
</node>

All the presentational whitespace surrounding "Some text" is part of
the value (the first carriage return, the indentation and the second
CR), which is not the intention.

Having mixed content like that isn't really suitable for data-centric
XML as this problem has demonstrated - its much better to have an
element for each value, and each element should only contain other
elements, or text, but not both eg:

<node>
   <child/>
   <child>Some text</child>
</node>

cheers
andrew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.