XQuery strange result
Added by Anonymous about 17 years ago
Legacy ID: #4663879 Legacy Poster: lolo77 (lolo77)
Hello, I have simple XQuery, which should return all records with duplicite field types: <a> { let $doc := doc('in.xml') for $record in $doc/a/record, $field-type in distinct-values($doc/a/record/field/@type) where count($record/field[@type=$field-type])>1 return <b> {$record} <field-type> {$field-type} </field-type> <size> {count($record/field[@type=$field-type])} </size> </b> } </a> Input: <a> <record> <field type="200" b="1"/> <field type="200" a="2"/> </record> <record> <field type="100" b="1"/> <field type="200" a="3"/> </record> <record> <field type="100" b="1"/> <field type="300" a="3"/> <field type="300" a="4"/> </record> </a> But the result is strange (I am new to XQuery). It returns record with non-duplicite fields (see <size>1</size>, there should not be such record): <?xml version="1.0" encoding="UTF-8"?> <a> <b> <record> <field type="200" b="1"/> <field type="200" a="2"/> </record> <field-type>200</field-type> <size>2</size> </b> <b> <record> <field type="100" b="1"/> <field type="200" a="3"/> </record> <field-type>200</field-type> <size>1</size> </b> <b> <record> <field type="100" b="1"/> <field type="300" a="3"/> <field type="300" a="4"/> </record> <field-type>300</field-type> <size>2</size> </b> </a> Is it bug in saxon9? When I exchange variables in for clause, result is correct.
Replies (2)
RE: XQuery strange result - Added by Anonymous about 17 years ago
Legacy ID: #4664053 Legacy Poster: Michael Kay (mhkay)
Yes, this is indeed a bug - an incorrect optimization. Details at http://sourceforge.net/tracker/index.php?func=detail&aid=1846246&group_id=29872&atid=397617 There's a patch in Subversion, but as a workaround you can inhibit the optimization by writing where count($record/field[@type=$field-type])+1 > 2
RE: XQuery strange result - Added by Anonymous about 17 years ago
Legacy ID: #4664068 Legacy Poster: lolo77 (lolo77)
Thanks a lot. It was my second xquery in my life, so I was confused :)
Please register to reply