developers

    Forum Stats

  • 3,873,884 Users
  • 2,266,627 Discussions
  • 7,911,651 Comments

Discussions

How to do count and divide by 10 in xquery

User_CROFU
User_CROFU Member Posts: 40 Blue Ribbon
edited Jul 31, 2013 7:41AM 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.


Regards

Phanindra.

Answers

  • odie_63
    odie_63 Member Posts: 8,493 Silver Trophy

    Hi,

    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.

This discussion has been closed.
developers