Subject: [xsl] Re: more elegant way to process element with default value? From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Fri, 13 Jun 2003 22:05:00 +0200 |
(1) <xsl:variable name="someName" select="concat(substring('true', 1, 4 - 4 * (not($tmp))), $tmp)"/> Or (I prefer this): (2) string($default[not($tmp)] | $tmp) $default is a node-set defined in the stylesheet such that its string value is "true" , e.g.: <myDefault:myDefault>true</myDefault:myDefault> <xsl:variable name="default" select="document('')/*/myDefault:*[1]"/> (3) An elegant way is what David Carlisle demonstrated with creating multiple attributes with the same name. ===== Cheers, 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] more elegant way to proce, Steve Rosenberry | Thread | RE: [xsl] Re: more elegant way to p, Lars Huttar |
Re: [xsl] how to view html not xml/, Steve Rosenberry | Date | RE: [xsl] href problem...using CDAT, Passin, Tom |
Month |