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

Selecting first descendant text node

Subject: Selecting first descendant text node
From: Christian Roth <roth@xxxxxxxxxxxxxx>
Date: Fri, 11 Jan 2002 15:23:20 +0100
descendant text
Hello,

how do I select the first descendant text node of an element?

My XML:

..
  <item numbertext="1. ">
    <par>
      <italic>first text</italic>
    </par>
    <par>next text</par>
  </item>
..


The stylesheet should put the numbertext attribute value before the first
textnode of the contents of the <item> element, i.e. expected result
should be:

..
  <item>
    <par>
      <italic>1. first text</italic>
    </par>
    <par>next text</par>
  </item>
..


First try:

..
<xsl:template match="item//text()[1]">
    <xsl:value-of select="ancestor::item/attribute::numberingtext" />
    <xsl:value-of select="." />
</xsl:template>
..

This does not work since it matches both text nodes, since ...text()[1]
matches only for first child of its immediate parent, which is true for
both text nodes.


Second try:

..
<xsl:template match="(item//text())[1]">
    <xsl:value-of select="ancestor::item/attribute::numberingtext" />
    <xsl:value-of select="." />
</xsl:template>
..

This does not work since the XSLT processor complains of illegal tokens
"item", "/", etc. after the first opening bracket in the match expression.

So, how do I select the first (in document order) of all of the
descendant text nodes of an element?

I was using Xalan 2.1.0 for the test.

Regards, Christian.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.