Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Setting a a variable to a default value Setting a a variable to a default valueTo: NULL Date: 12/4/2008 7:23:00 AM Hi all,
XSL Novice
In the source XML I have a Display_Count node that is the
number of lines to display in the output HTML generated by
my XSL.
So for example, if <Display_Count>10</Display_Count> I get 10
lines, if <Display_Count>5</Display_Count> I get 5.
I set a variable loop_num to be used as a loop counter later
in the XSL as follows:
<xsl:variable name="loop_num" select="//Display_Count"/>
This works fine.
Now I want to handle the case where the Display_Count node
does not exist in the XML input. That is, I want to set a
default value (say, of 3) for loop_num in that case.
I ran into the problem where a variable cannot be reassigned
and its definition cannot be duplicated in the current scope.
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>
How can I set the varable loop_num to some default constant
value if the Display_Count node does not exist or to the value
of the Display_Count node if it does exist?
Thanks
kpg
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
