Connecting Tech Pros Worldwide Help | Site Map

xsl:when: Result-Tree-Fragment Question

Newbie
 
Join Date: Jul 2009
Posts: 4
#1: Jul 17 '09
Hi all,

I'm creating a number of fragments to calculate various presence numbers. I'm creating variables from the results of these fragments then doing simple math to give the results.

I'm having an error when trying to add two variables (from the result-tree-fragment) when one variable has no value at all. In the source XML, the criteria returns no matches, so when the two variables are added, it returns NaN. I'm Trying to make a xsl:choose to determine the presence of a null fragment return, but can't seem to get the correct test attribute working.

Here's the XSLT 1.0code:

Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="SophFemalePTNexusTC">
  2.     <xsl:for-each-group select="Census/Student
  3.         [(
  4.         (Gender='Female') and
  5.         (Classification='nexus') and
  6.         (@AdmitTerm='Fall Semester 2008') and
  7.         (TotCredits/@Load&lt;8) and
  8.         (TotCredits/@TransferCredits&gt;29.99) and
  9.         (TotCredits/@TransferCredits&lt;60)
  10.         )]" 
  11.         group-by="/">
  12.         <xsl:value-of select="count(current-group())"/>
  13.     </xsl:for-each-group>
  14. </xsl:variable>
  15.  
  16. <xsl:variable name="SophFemalePTNexusUG">
  17.     <xsl:for-each-group select="Census/Student
  18.         [(
  19.         (Gender='Female') and
  20.         (Classification='nexus') and
  21.         (TotCredits/@Load&lt;8) and
  22.         (TotCredits/@UG&gt;29.99) and
  23.         (TotCredits/@UG&lt;60)
  24.         )]" 
  25.         group-by="/">
  26.         <xsl:value-of select="count(current-group())"/>
  27.     </xsl:for-each-group>
  28. </xsl:variable>
  29.  
  30. <xsl:choose>
  31.     <xsl:when test="boolean($SophFemalePTNexusTC)='1'">
  32.         <xsl:value-of select="$SophFemalePTNexusUG + 0"/>
  33.     </xsl:when>
  34.     <xsl:otherwise>
  35.         <xsl:value-of select="$SophFemalePTNexusUG + $SophFemalePTNexusTC"/>
  36.     </xsl:otherwise>
  37. </xsl:choose>
  38.  
I highlighted where the error is. In This example, there is no RTF for the variables $SophFemalePTNexusTC. For example, if I do a <Value-of select:$SophFemalePTNexusTC, it will return nothing.

The result of the above code picks the xsl:when, and not the xsl:otherwise as it should if properly testing the presence of a null RTF.

The boolean is the wrong process - as the RTF is not a number or a string (right?) it is not subject to a boolean, count, or number attribute? Any help would be greatly appreciated.
Newbie
 
Join Date: Jul 2009
Posts: 4
#2: Jul 18 '09

re: xsl:when: Result-Tree-Fragment Question


Think the following solution worked. It's giving me the proper when/otherwise outcomes that I would expect... however, I'm still suspicious. Is this a dangerous way or not a good way in testing a RTF?

Expand|Select|Wrap|Line Numbers
  1. <xsl:choose>
  2.     <xsl:when test="string($SophFemalePTNexusTC - $SophFemalePTNexusTC)='NaN'">
  3.         <xsl:value-of select="$SophFemalePTNexusUG"/>
  4.     </xsl:when>
  5.     <xsl:otherwise>
  6.         <xsl:value-of select="$SophFemalePTNexusUG - $SophFemalePTNexusTC"/>
  7.     </xsl:otherwise>
  8. </xsl:choose>
  9.  
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#3: Jul 22 '09

re: xsl:when: Result-Tree-Fragment Question


I would consider testing if the variable is equal to the empty string, eg = ''
Reply