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

RE: choose to define conditional attributes?

Subject: RE: choose to define conditional attributes?
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Thu, 30 Sep 1999 15:02:44 -0600
xsl attribute conditional
> <label>
>   <xsl:attribute name="id">myLabelId</xsl:attribute>
>   <xsl:choose>
>     <xsl:when test=". = ''">
>       <xsl:attribute name="style">MyStyleEmpty</xsl:attribute>
>     </xsl:when>
>     <xsl:otherwise>
>       <xsl:attribute name="style">MyStyleFull</xsl:attribute>
>     </xsl:otherwise>
>   </xsl:choose>
>   The Label
> </label>

http://www.w3.org/TR/xslt#creating-attributes says, "Instantiating an
xsl:attribute element adds an attribute node to the containing result
element node". It's not terribly clear, but the "containing" node is the
<xsl:attribute>'s parent, which is <xsl:when> in your example. You want the
parent to be a result element, i.e. a literal result element like <label> or
an <xsl:element> instruction.

Furthermore, <xsl:choose>...</xsl:choose> gets replaced by characters. If
there were some non-whitespace characters in the <xsl:when> or
<xsl:otherwise>, you'd end up with those being inserted right before "  The
Label" in the content of <label>. You really want the characters to end up
inside your <xsl:attribute>.

Try it this way instead:

<label>
  <xsl:attribute name="id">myLabelId</xsl:attribute>
  <xsl:attribute name="style">
    <xsl:choose>
      <xsl:when test=". = ''">
        <xsl:value-of select="'MyStyleEmpty'"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="'MyStyleFull'"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
  The Label
</label>


 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.