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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ems9tech
    New Member
    • Apr 2009
    • 12

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

    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:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <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">
        <Form UFI="100082841" Address1="111 PENN AVENUE" City="PITTSBURGH" State="PA" Zip="15209">
        <Individual UCI="900236487" FirstName="RACHEL">
          <Income IncomeType="8" />
        </Individual>
        <Individual UCI="900236488" FirstName="RUSSELL">
          <Income IncomeType="8" />
        </Individual>
        <Individual UCI="900236489" FirstName="REBECCA">
          <Income IncomeType="8" />
        </Individual>
        <Individual UCI="900236490" FirstName="MARY">
          <Income IncomeType="8" />
        </Individual>
      </Form>
    </CFF>
    I've tried this several different ways in this sample XSL stylesheet:
    Code:
    <?xml version="1.0"?>
    <!-- key.xsl -->
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:output method="html"/>
    
        <xsl:variable name="Test_Count1">
            <xsl:number value="count(/CFF/Form/Individual/Income[@IncomeType='1' or @IncomeType='8'])" level="any" format="01"/>"
        </xsl:variable>
    
        <xsl:variable name="Test_Count2">
            <xsl:number value="count(//CFF//Form//Individual/Income[@IncomeType=1 or @IncomeType=8]) "/>"
        </xsl:variable>
    
        <xsl:variable name="Test_Count3">
            <xsl:value-of select="count(//CFF//Form//Individual/Income[@IncomeType=1 or @IncomeType=8]) "/>"
        </xsl:variable>   
       
        <xsl:template match="/">
            <html>
                <head>
                    <title>
                        <xsl:text>Count TEST </xsl:text>
                    </title>
                </head>
                <body style="font-family: sans-serif;">
                    <xsl:call-template name ="TEST_VARIABLES"/>
                </body>
            </html>
        </xsl:template>
    
        <xsl:template name="TEST_VARIABLES">
            <!-- TEST printing values to debug -->
            <p align="left">
                Test_Count1:  <xsl:value-of select="number($Test_Count1)"/>
                <br/>
                Test_Count2:  <xsl:value-of select="$Test_Count2"/>
                <br/>
                Test_Count3:  <xsl:number value="$Test_Count3"/>
            </p>
        </xsl:template>
    
    </xsl:stylesheet>
    Results:

    Test_Count1: NaN
    Test_Count2: 4"
    Test_Count3: NaN
    Last edited by jkmyoung; Apr 8 '09, 06:43 PM. Reason: [code] tags
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    $Test_Count1: Due to the extra " on the end, it is a number than a string -> finally a string. You get:
    Code:
    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:
    Code:
        <xsl:variable name="Test_Count3" select="count(//CFF//Form//Individual/Income[@IncomeType=1 or @IncomeType=8]) "/>

    Comment

    • ems9tech
      New Member
      • Apr 2009
      • 12

      #3
      That's it !!!

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

      Comment

      Working...