[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 21:00:16 -0500
refer to node by name
Sorry, I realized later that you were not in the node-and-text
problem camp, but that you wanted to rename the nodes according
to a fixed sequence.  Here is a neat way of doing that, 
exploiting the fact that document('') refers to the stylesheet 
document.

 Steve

<?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="customer">
  <xsl:copy>
    <xsl:for-each select="*">
      <xsl:variable name="index" select="position()"/>
      <xsl:element name="{document('')//field[$index]}">
        <xsl:value-of select="normalize-space(.)"/>
      </xsl:element>
    </xsl:for-each>
  </xsl:copy>
</xsl:template>

<xsl:template name="fieldnames">
  <field>street</field>
  <field>city</field>
  <field>state</field>
</xsl:template>

</xsl:stylesheet>

produces:

<?xml version="1.0" encoding="utf-8"?>
<customer><street>1 Main
Street</street><city>Pittsburgh</city><state>PA</state></customer>

from:

<customer>
 <node>1 Main Street</node>
 <node>Pittsburgh</node>
 <node>PA</node>
</customer>


 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.