Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Setting a a variable to a default value [Thread Next] Re: Setting a a variable to a default valueTo: NULL Date: 12/4/2008 7:25:00 PM > With XSLT 2.0 you could use the much shorter > <xsl:variable name="loop_num" > select="if (not(//Display_Count)) then 3 else > //Display_Count"/> This will select //Display_Count nodes, but the OP needs just one (as this question was asked for XSLT 1.0) A correct and shorter XPath 2.0 solution is the following: ( //Display_Count, 3)[1] Cheers, Dimitre Novatchev "Martin Honnen" <mahotrash@y...> wrote in message news:O2gWFaiVJHA.2928@T...... > kpg wrote: > >> So something like this will not work: >> >> <xsl:choose> >> <xsl:when test="not(//Display_Count)"> >> <xsl:variable name="loop_num" select="1"/> </xsl:when> >> <xsl:otherwise> >> <xsl:variable name="loop_num" select="//Display_Count"/> >> </xsl:otherwise> >> </xsl:choose> > > The other way round works: > <xsl:variable name="loop_num"> > <xsl:choose> > <xsl:when test="not(//Display_Count)">3</xsl:when> > <xsl:otherwise> > <xsl:value-of select="//Display_Count"/> > </xsl:otherwise> > </xsl:choose> > </xsl:variable> > > With XSLT 2.0 you could use the much shorter > <xsl:variable name="loop_num" > select="if (not(//Display_Count)) then 3 else > //Display_Count"/> > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
