exclude Null node in XSL?

Last post 07-03-2008 10:14 PM by hbcontract2002. 4 replies.

Sort Posts:

  • exclude Null node in XSL?

    07-03-2008, 9:26 AM

    Hi, I have a sample XML like below ...

    <test>
     <ROW>
      <Category>A</Category>
      <Number>10</Number>
      <Category_2>B</Category_2>
      <Number_2>50</Number_2>
     </ROW>
     <ROW>
      <Category>AA</Category>
      <Number>60</Number>
      <Category_2>BB</Category_2>
      <Number_2>100</Number_2>
     </ROW>
     <ROW>
      <Category>A</Category>
      <Number>10</Number>
      <Category_2 />
      <Number_2 />
     </ROW>
    </test>

    I am trying to get the sum from Number_2 ... noticed 3rd row has null value for Number_2 and this returns NaN.
    How do I get the sum or average [using sum of Number_2 divided by "total of Number_2 nodes (excluding those null node)"]?

    I tried nomalized-space(.) ... didn't work either. PLEASE HELP!!

  • Re: exclude Null node in XSL?

    07-03-2008, 10:57 AM

     You will need to use a xsl:if or choose.

     <xsl:if test="string-length(Number_2) != 0">
     

    If I was helpful, please mark "answered" so I can get credit. Thanks!
  • Re: exclude Null node in XSL?

    07-03-2008, 11:55 AM

    tried that before, didn't work either.

  • Re: exclude Null node in XSL?

    07-03-2008, 12:14 PM

     Well since you haven't shown your xslt, than there is not much me I can help you with. Try posting your xml input, xslt and desired output.

    If I was helpful, please mark "answered" so I can get credit. Thanks!
  • Re: exclude Null node in XSL?

    07-03-2008, 10:14 PM

    I found the problem. It was the file formated wrongly. I was converting a csv file to xml using comma as delimeter. There is a column that has comma as a data ... so causing the problem. Thanks anyway.

Page 1 of 1 (5 items)
Microsoft Communities
Page view counter