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

RE: Newby Question reformatting xml

Subject: RE: Newby Question reformatting xml
From: cknell@xxxxxxxxxx
Date: Mon, 17 Feb 2003 09:36:49 -0500
RE:  Newby Question reformatting xml
-----Original Message-----
From:     "Michael A. Thompson" <mathomp@xxxxxxxxxxxxxx>

<xsl:template match="BBB">
  <xsl:element name="BBB">
    <xsl:attribute name="num">
      <xsl:value-of select="//DDD/@id">
      </xsl:value-of>
    </xsl:attribute>
    <xsl:value-of select="."></xsl:value-of></xsl:element>
</xsl:template>

Your problem is with the XPath expression "//DDD/@id". It selects the first node that matches this pattern, which, of course, is only correct for the children of the first <DDD> element. Use this expression instead:


"parent::node()/attribute::id"

or in abbreviated format:

"../@id"

While the latter is more concise, the former is easier to understand. Both expressions evaluate identically.

If you are going for brevity, you could re-write the template so:

<xsl:template match="BBB">
  <xsl:element name="BBB">
    <xsl:attribute name="num"><xsl:value-of select="../@id" /></xsl:attribute>
    <xsl:value-of select="." />
  </xsl:element>
</xsl:template>


-- Charles Knell cknell@xxxxxxxxxx - email



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.