Connecting Tech Pros Worldwide Help | Site Map

xsl count of matching attributes returns number plus " or NaN....

Newbie
 
Join Date: Apr 2009
Posts: 12
#1: Apr 8 '09
I can't get this count to return a number without an empty quote at the end ( " ) or getting NaN. Does anyone know why? I've searched and don't see any other postings on this issue. I'm using VS 2008. Thanks for any and all pointers!!!

XML file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <CFF xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" FormCount="1" TotalFormCount="501" FileSubmitDate="2009-03-26">
  3.     <Form UFI="100082841" Address1="111 PENN AVENUE" City="PITTSBURGH" State="PA" Zip="15209">
  4.     <Individual UCI="900236487" FirstName="RACHEL">
  5.       <Income IncomeType="8" />
  6.     </Individual>
  7.     <Individual UCI="900236488" FirstName="RUSSELL">
  8.       <Income IncomeType="8" />
  9.     </Individual>
  10.     <Individual UCI="900236489" FirstName="REBECCA">
  11.       <Income IncomeType="8" />
  12.     </Individual>
  13.     <Individual UCI="900236490" FirstName="MARY">
  14.       <Income IncomeType="8" />
  15.     </Individual>
  16.   </Form>
  17. </CFF>
  18.  
I've tried this several different ways in this sample XSL stylesheet:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <!-- key.xsl -->
  3. <xsl:stylesheet version="1.0"
  4.   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  5.  
  6.     <xsl:output method="html"/>
  7.  
  8.     <xsl:variable name="Test_Count1">
  9.         <xsl:number value="count(/CFF/Form/Individual/Income[@IncomeType='1' or @IncomeType='8'])" level="any" format="01"/>"
  10.     </xsl:variable>
  11.  
  12.     <xsl:variable name="Test_Count2">
  13.         <xsl:number value="count(//CFF//Form//Individual/Income[@IncomeType=1 or @IncomeType=8]) "/>"
  14.     </xsl:variable>
  15.  
  16.     <xsl:variable name="Test_Count3">
  17.         <xsl:value-of select="count(//CFF//Form//Individual/Income[@IncomeType=1 or @IncomeType=8]) "/>"
  18.     </xsl:variable>   
  19.  
  20.     <xsl:template match="/">
  21.         <html>
  22.             <head>
  23.                 <title>
  24.                     <xsl:text>Count TEST </xsl:text>
  25.                 </title>
  26.             </head>
  27.             <body style="font-family: sans-serif;">
  28.                 <xsl:call-template name ="TEST_VARIABLES"/>
  29.             </body>
  30.         </html>
  31.     </xsl:template>
  32.  
  33.     <xsl:template name="TEST_VARIABLES">
  34.         <!-- TEST printing values to debug -->
  35.         <p align="left">
  36.             Test_Count1:  <xsl:value-of select="number($Test_Count1)"/>
  37.             <br/>
  38.             Test_Count2:  <xsl:value-of select="$Test_Count2"/>
  39.             <br/>
  40.             Test_Count3:  <xsl:number value="$Test_Count3"/>
  41.         </p>
  42.     </xsl:template>
  43.  
  44. </xsl:stylesheet>
  45.  
Results:

Test_Count1: NaN
Test_Count2: 4"
Test_Count3: NaN
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#2: Apr 8 '09

re: xsl count of matching attributes returns number plus " or NaN....


$Test_Count1: Due to the extra " on the end, it is a number than a string -> finally a string. You get:
Expand|Select|Wrap|Line Numbers
  1. 04"
The processor doesn't know how to interpret 04" as a number, so throws that value.

$Test_Count3: By using <xsl:value-of> when creating your variable, you've created a result tree fragment, a set of result nodes. Again, the processor doesn't know how to convert the nodes into a number, so throws an error. Also, you have an extra quote " at the end of the value.
I would suggest using instead:
Expand|Select|Wrap|Line Numbers
  1.     <xsl:variable name="Test_Count3" select="count(//CFF//Form//Individual/Income[@IncomeType=1 or @IncomeType=8]) "/>
Newbie
 
Join Date: Apr 2009
Posts: 12
#3: Apr 8 '09

re: xsl count of matching attributes returns number plus " or NaN....


I had an extra '' added to the end of the line without realizing it! Much thanks!!!
Reply