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

RE: Getting the text node

Subject: RE: Getting the text node
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 12 Oct 2005 22:40:43 +0100
textnode bold
> Hi all,
>   I have a beginners question regarding capturing of
> text node and tags within it, with this example:

Well (a) you can't have elements within a text node, and (b) nodes appear in
the tree view of an XML document, while tags appear only in the lexical
view, so you're badly mixing up your concepts.

If the lexical view is

<span>Some <bold>strong</bold> text</span>

then the tree view contains two elements (span and bold) and three text
nodes ("Some ", "strong", and " text"). 
> 
> <root>
> <p>
> <span>
> <field>Data1</field>
> </span>Some bold <b>text here</b>.
> </p>
> <p>
> <span>
> <field>Data2</field>
> </span>Sample data that needs to appear <b>bold</b>
> and <it>ital</it>.
> </p>
> </root>
> 
> output:
> 
> <Data1>Some bold <bold>text here</bold>.</Data1>
> <Data2>Sample data that needs to appear
> <bold>bold</bold> and <ital>ital</ital>.</Data2>
> 
> here is XSL:
> 
> <xsl:template match="p">
>         <xsl:apply-templates select="span"/>
> </xsl:template>
> 
> <xsl:template match="span">
>  <xsl:element name="{field/text()}">
>     <xsl:value-of select="following::text()[1]"/>
>  </xsl:element>
> </xsl:template>

Replace

<xsl:value-of select="following::text()[1]"/>

with

<xsl:copy-of select="following-sibling::node()"/>

because

(a) you only want to copy siblings of the span element (children of the same
p element), not everything in the rest of the document (which is what
following:: does)

(b) you want to copy elements (such as the bold element) as well as text
nodes, and

(c) you want to copy the nodes as a tree structure rather than reducing them
all to plain text which is what xsl:value-of does.

Michael Kay
http://www.saxonica.com/

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.