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

Re: Do you know how to refer to a node?

Subject: Re: Do you know how to refer to a node?
From: Steve Tinney <stinney@xxxxxxxxxxxxx>
Date: Sun, 19 Dec 1999 19:50:22 -0500
xml xsl refer node
Jonathan Asbell wrote:
> 
> I need to refer to
> node(0)
> node(1)
> node(2)
> etc. which are children of a node "CUSTOMER".   How do I refer to each
> successive node child of node "CUSTOMER"?  My aim is to transform this into
> xml with more meaningful tag names
> 
> <CUSTOMER>
> <xsl:text>WHITC</xsl:text>
> <xsl:text>White Clover Markets</xsl:text>
> <xsl:text>Karl Jablonski</xsl:text>
> <xsl:text>Owner</xsl:text>
> <xsl:text>305 - 14th Ave. S.<BR>Suite 3B</xsl:text>
> <xsl:text>Seattle</xsl:text>
> <xsl:text>WA</xsl:text>
> <xsl:text>98128</xsl:text>
> <xsl:text>USA</xsl:text>
> <xsl:text>(206) 555-4112</xsl:text>
> <xsl:text>(206) 555-4115</xsl:text>
> </CUSTOMER>
> 

Is your input really marked up with <xsl:text>?  Assuming input
like this:

<nodes>
 <a>1</a>
 lalala
 <b>2</b>
</nodes>

You can either let your templates do the walking:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="nodes"/>

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

<xsl:template match="nodes">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="*|text()">
  <node>
    <xsl:value-of select="normalize-space(.)"/>
  </node>
</xsl:template>

</xsl:stylesheet>

Or iterate over the node list explicitly:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="nodes"/>

<xsl:template match="/">
  <nodes>
    <xsl:for-each select="/nodes/node()">
      <node><xsl:value-of select="normalize-space(.)"/></node>
    </xsl:for-each>
  </nodes>
</xsl:template>

</xsl:stylesheet>

 Steve


 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.