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

Re: more elegant way to process element with default v

Subject: Re: more elegant way to process element with default value?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 13 Jun 2003 22:05:00 +0200
elegant names
  <xsl:variable name="someName" select="concat(substring('true', 1, 4 - 4 *
(not($tmp))), $tmp)"/>

Or (I prefer this):

string($default[not($tmp)] | $tmp)

$default is a node-set defined in the stylesheet such that its string value
is "true"  , e.g.:


<xsl:variable name="default" select="document('')/*/myDefault:*[1]"/>

An elegant way is what David Carlisle demonstrated with creating multiple
attributes with the same name.


Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"Steve Rosenberry" <Steve.Rosenberry@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:3EEA242C.1FC6E272@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Lars Huttar wrote:
> >
> >   <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?
> >
> Wow, Lars, if you consider that verbose I must be doing something
> terribly wrong...
> Assuming, all your global settings follow the same basic XPath
> structure, I'd do it as follows:
>    <xsl:variable name="number-rows">
>      <xsl:call-template name="get_global_setting">
>        <xsl:with-param name="setting" select="'number-rows'"/>
>      </xsl:call-template>
>    </xsl:variable>
> and then provide the appropriate get_global_setting named template.  If
> your XPath structure doesn't allow for the simple syntax above, you can
> always change the "setting" parameter to a "path" parameter.
> In an actual XSLT file, I would write the entire variable declaration
> above on a single line to get most of the verbosity out of my face.  As
> an added benefit, if the retrieval method for your global settings
> changes, you only have a single place to change your XSLT.
> -- 
> Steve Rosenberry
> Sr. Partner
> Electronic Solutions Company -- For the Home of Integration
> http://ElectronicSolutionsCo.com
> (610) 670-1710
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

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

Current Thread


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.
First Name
Last Name
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.