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

more elegant way to process element with default value

Subject: more elegant way to process element with default value?
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Fri, 13 Jun 2003 13:49:12 -0500
llcd
Hi all,
I'm trying to set a (global) variable from a global-settings/setting
element in my source XML document, but I want this variable to have a default
value if the desired <setting> element doesn't exist.  E.g. my XML source:

<llcd:llc-display>
  <llcd:global-settings>
    <llcd:setting name="number-rows">false</setting>
    ...
  </llcd:global-settings>
  ...
</llcd:llc-display>

I want to set a number-rows variable in my stylesheet to
    /*/global-settings/setting[@name='number-rows']
but I want the variable to contain 'true' if such a <setting>
node doesn't exist in the input document.

I'm doing it like this so far:
  <xsl:variable name="number-rows">
    <xsl:variable name="tmp" select="/*/llcd:global-settings/llcd:setting[@name = 'number-rows']"
/>
    <xsl:choose>
      <xsl:when test="$tmp"><xsl:value-of select="$tmp" /></xsl:when>
      <xsl:otherwise><xsl:value-of select="'true'" /></xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

But that seems pretty verbose.  And it will be worse as I have multiple
settings variables with various names.
Is there a more elegant way?

(You may ask why I don't put the value 'true' in an attribute and
just set a default for it in the DTD.  The reason is that some settings
will have values that must be arbitrary text, and my understanding is that
certain kinds of character data cannot be stored in attribute values,
since they are CDATA not PCDATA. Am I mistaken about this?)

Thanks,
Lars


 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.