473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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:
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
Apr 8 '09 #1
2 5554
jkmyoung
2,057 Expert 2GB
$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]) "/>
Apr 8 '09 #2
I had an extra '' added to the end of the line without realizing it! Much thanks!!!
Apr 8 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Victor | last post by:
Hi, I have some sample XML and an XSD below I have written. The XSD almost does what I want. What I need is some way of enforcing that AT LEAST TWO of the attributes "TestAttribute" are "X". ...
4
by: vacataire testeur de site web | last post by:
Bonjour je cherche à afficher de count de tables identiques dans la forme exemple num_cli | nombre de poste | nombre de voiture 1 1 3 2 2 ...
9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
2
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
2
by: Julio Allegue | last post by:
I am getting the wrong Count(*) on vb.net using the ExecuteScalar . It returns all the rows. It doesn't seem to look at the WHERE clause. At the same time, I am getting the correct count on "SQL...
0
by: Peter Rilling | last post by:
I am working on trying to compare "titles" from two different lists and trying to determine the most likely match. When a similar entry appears in both, the result works well, but what I need to...
8
by: regis | last post by:
Greetings, about scanf matching nonempty sequences using the "%" matches a nonempty sequence of anything except '-' "%" matches a nonempty sequence of anything except ']" matches a nonempty...
2
by: jonathan184 | last post by:
Hi I am having a problme where the results of the sql count is not matching the results of the perl script sql count. The script was working fine up till Wed last week and after that the results...
2
by: MichiMichi | last post by:
My asp.net application has a directory which is filled up with over 17 files (email) a second. After a while this sums up into a huge amount of files. I usually count files with the GETFILES...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.