Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Setting a a variable to a default value

From: kpg <no@----.--->
To: 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



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent