[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Hello Hans,
there is one possibility, which is maybe more difficult to maintain, but is much shorter:
<xsl:value-of select="$title[$title != ''] | $title2['pseudocode: if second condition true'] | $title3['pseudo: if 3rd true'] | $default-value"/>
But there are some aspects:
1. The selected value will generally be the first in document order, not the first in the select statement. You won't get the hard and exclusive order of <xsl:choose/>, <xsl:when/>, <xsl:otherwise/>.
2. It will only work with node-sets, not with strings. So instead of testing on $title, you will need the expression used in your variable $title:
<xsl:value-of select="$pathNode[.=$df]/../@title[normalize-space()] | $expression2['pseudo: if true'] | $pathProperties/df[@name=$df]"/>
It's maybe a bit hard to understand. But you only have one <xsl:when/> in your example, so I can't give you a better example.
Of course instead of <xsl:value-of/> you can use <xsl:variable/>, but you will get all nodes, for which the evaluation is true. This means you always get the default node too. So you must change it a bit:
<xsl:variable name="title" select="(like select above)[1]"/>
Joerg
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Re: [xsl] optimization choose - then same call-template
Subject: Re: [xsl] optimization choose - then same call-template From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Sun, 26 Jan 2003 14:06:30 +0100 |
Hello Hans,
there is one possibility, which is maybe more difficult to maintain, but is much shorter:
<xsl:value-of select="$title[$title != ''] | $title2['pseudocode: if second condition true'] | $title3['pseudo: if 3rd true'] | $default-value"/>
But there are some aspects:
1. The selected value will generally be the first in document order, not the first in the select statement. You won't get the hard and exclusive order of <xsl:choose/>, <xsl:when/>, <xsl:otherwise/>.
2. It will only work with node-sets, not with strings. So instead of testing on $title, you will need the expression used in your variable $title:
<xsl:value-of select="$pathNode[.=$df]/../@title[normalize-space()] | $expression2['pseudo: if true'] | $pathProperties/df[@name=$df]"/>
It's maybe a bit hard to understand. But you only have one <xsl:when/> in your example, so I can't give you a better example.
Of course instead of <xsl:value-of/> you can use <xsl:variable/>, but you will get all nodes, for which the evaluation is true. This means you always get the default node too. So you must change it a bit:
<xsl:variable name="title" select="(like select above)[1]"/>
Hope this helps a bit. Regards,
Joerg
<!-- the three parameters are inititialized from other template rule, which applies this rule for node df > <xsl:template match="df"> <xsl:param name="pathNode"/> <xsl:param name="pathProperties"/> <xsl:param name="df" select="@name"/> <!-- select attribute title from xml-source with normalizing (delete)white-space--> <xsl:variable name="title" select="normalize-space($pathNode[.=$df]/../@title)"/> <xsl:choose> <!-- test if title from xml-source is not empty (exist and contains more than white-space)--> <xsl:when test="$title != '' "><!-- Label --><xsl:value-of select="$title"/> <xsl:call-template name="df"> <!-- insert title from xml-source and pass parameters to generic template for generation of datafields --> <xsl:with-param name="thisTitle" select="$title"/> <xsl:with-param name="thisName" select="$df"/> <xsl:with-param name="thisPath" select="$pathNode[.=$df]/../."/> <xsl:with-param name="dfProperties" select="$pathProperties/df[@name=$df]"/> </xsl:call-template> </xsl:when> <!-- title from xml-properties --> <xsl:otherwise> <!-- Label --><xsl:value-of select="$pathProperties/df[@name=$df]"/> <xsl:call-template name="df"> <!-- insert title from xml-properties and pass same parameters as above to generic template for generation of datafields --> <xsl:with-param name="thisTitle" select="$pathProperties/df[@name=$df]"/> <xsl:with-param name="thisName" select="$df"/> <xsl:with-param name="thisPath" select="$pathNode[.=$df]/../."/> <xsl:with-param name="dfProperties" select="$pathProperties/df[@name=$df]"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] optimization choose - then sa, "Braumüller, Hans" | Thread | [xsl] basic xsl question, Matts Isuls |
Re: [xsl] xsl:copy question, Joerg Heinicke | Date | RE: [xsl] [off-list] document(lang_, B. Tommie Usdin |
Month |