RE: <xsl:copy-of> question

Subject: RE: <xsl:copy-of> question
From: "Hunter, David" <dhunter@xxxxxxxxxxxx>
Date: Thu, 16 Dec 1999 17:29:31 -0500
Thanks to all who responded to this.  Unfortunately, I was hoping to use
<xsl:copy-of>, not <xsl:copy>, because this was for an example in a book,
but I'll find another example to use for <xsl:copy-of>.  :-)

(And, for that matter, probably use this example for <xsl:copy>...)

-----Original Message-----
From: Hunter, David 
Sent: Wednesday, December 15, 1999 3:50 PM
To: 'XSL-list'
Subject: <xsl:copy-of> question


Suppose I have the following XML:

<employee FullSecurity="0">
  <name>John Doe</name>
  <department>Widget Sales</department>
  <phone>(555)555-5555<extension>2974</extension></phone>
  <salary>62,000</salary>
  <area>3</area>
</employee>

I want to create a very simple XSL stylesheet which does the following:  If
the FullSecurity attribute evaluates to "true", then copy all of the source
tree to the result tree.  If the FullSecurity attribute evaluates to
"false", copy all of the source tree *except for the <salary> element* to
the result tree.  The closest I can get is something like the following:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="number(/employee/@FullSecurity)"><xsl:copy-of
select="/"/></xsl:when>
    <xsl:otherwise>
      <employee>
        <xsl:copy-of select="//name | //department | //phone | //area"/>
      </employee>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
</xsl:stylesheet>

Is there a more succinct way of saying "copy all of the <employee> element
to the result tree *except* for the <salary> element"?

If it matters, I'm using the Win32 executable version of XT, but I want
something that's totally generic, so I'd rather not use extension functions.

David Hunter
MobileQ 
david.hunter@xxxxxxxxxxx 
http://www.MobileQ.com 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread