1 Reply Latest reply on Jul 31, 2013 11:41 AM by odie_63

    How to do count and divide by 10 in xquery


      Hi all,


      I need to count the number of elements and divide it by 10 in my xquery

      I am doing as below


      for $varabcd (1 to (fn:count($anyType1/*:adad)) div 10)


      when i run I am getting the below exception


      Error executing the XQuery transformation: Error parsing XML: line 11, column 67: {err}XP0006: "10 ({http://www.w3.org/2001/XMLSchema}decimal)": bad value for type {http://www.w3.org/2001/XMLSchema}integer

      could you please help me in this.



        • 1. Re: How to do count and divide by 10 in xquery



          Simple example :

          If the count() function returns 11, then 11 div 10 = 1.1 (datatype xs:decimal), and 1.1 is not a valid value for the sequence iterator, it must be an integer.


          At this point you have different options depending on how you want to round the value to an integer :

          • using fn:round()
          • using fn:floor()
          • using fn:ceiling()
          • casting to xs:integer directly : for $v in 1 to xs:integer(fn:count($anyType1/*:adad) div 10)


          Your choice.