RE: [xsl] Newby Question reformatting xml

Subject: RE: [xsl] Newby Question reformatting xml
From: cknell@xxxxxxxxxx
Date: Mon, 17 Feb 2003 09:36:49 -0500
-----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 select="."></xsl:value-of></xsl:element>

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:


or in abbreviated format:


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="." />

-- Charles Knell cknell@xxxxxxxxxx - email

XSL-List info and archive:

Current Thread