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

Re: In-order traversal of XHTML of text() and <foo> no

Subject: Re: In-order traversal of XHTML of text() and <foo> nodes?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 28 Mar 2003 16:13:30 +0000
xslt inorder traversal
Hi Gan,

> Say I have XML like this...
>
> <foobar>
>    Once <foo>upon</foo> a midnight <bar>dreary</bar> while I...
> </foobar>
>
> How do I make a traversal of that <foobar> node, picking up text(),
> <foo> and <bar> in document order, so as to pass through the text()
> but apply separate templates to <foo> and <bar>?

XSLT is designed to make this kind of transformation easy. Use the
<xsl:apply-templates> instruction to say "process the children of this
node" and the <xsl:template> element to say "when you find an element
X do Y":

<xsl:template match="foobar">
  <p><xsl:apply-templates /></p>
</xsl:template>

<xsl:template match="foo">
  <b><xsl:apply-templates /></b>
</xsl:template>

<xsl:template match="bar">
  <i><xsl:apply-templates /></i>
</xsl:template>

In this example, the text nodes are processed by a built-in template
that looks like:

<xsl:template match="text()">
  <xsl:value-of select="." />
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.