Wow ! I didn't know about that difference ! Thanks.

But this leads me to the question whether there is a possibility within the typeswitch statement that allows me to recognize whether this is an empty text node or a normal element() ?

If yes, let me know !


j.rebhan at schrieb am 08.03.06 12:54:12:

This is happening because you are counting whitespace text nodes as well as element nodes. Either replace child::node() by child::* (to select elements only), or use the command line option to cause whitespace to be stripped from source documents: -sa! ll.
For documents created within the query in a let expression, boundary whitespace is stripped by default.
Michael Kay

From: [] On Behalf Of Jochen Rebhan
Sent: 08 March 2006 11:33
To: saxon-hel!
Subject: [saxon] recursive function problem

Hi ,

I am having some problems reading an external file, the "no" attribute gets incremented by 2 instead of 1.

If I declare the external xml File as interal variable with "let", everyting works as expected, the "no" attribute gets incremented by 1.

Here the snippets:

(: the xquery file :)

xquery version "1.0";

declare variable $input external;

declare function local:copy($number_in as xs:integer, $node as element() , $level as xs:integer) as item()* {
    element { node-name($node ) }
        if ($level eq 1) then attribute no { $number_in } else (),
        for $! c at $number_out in $node/child::node() return
     &n! bsp;      typeswitch($c)
                case $e as element() return local:copy( $number_out, $e, $level + 1)
                case $t as text()    return $t
                default              return <error/>

local:copy(0,$input/*, 0)


(: the input file :)

<?xml version="1.0" encoding="UTF-8"?>
   &nb! sp;    <level1 attr="someatt">some text</level 1>
        <level1>some text v! alue</level1>
        < level1 attr="ter">some text</level1>
        <level1 someattr="something">
                <someelem>simple text</someelem>
                <someelems>simple textm</someelems>
        <level1 someattr="more text">
   !      </level1>
        <level1 someattr="some other text">
  &! nbsp;             <someelem>simple text1</someelem>
                <someelems>simple text2</someelems>
        <level1 someattr="sometext">
                <someelem attr="someatt">some text</someelem>
                <someelems attr="someatt">some text</someelems>


(: the windows .bat file I use! :)

java  -cp saxon8.jar net.sf.saxon.Query -o test.out.xml test.xq


(: the output looks like th! at, note the "no" attribute gets incremented by 2 instead of 1 :)

< P><?xml version="1.0" encoding="UTF-8"?>
        <level1 no="2">something</level1>
        <level1 no="4">some text</level1>
        <level1 no="6">some text value</level1>

Any idea why 2 ? As I said, when I define the Xml Input document as variable inside the Xquery file everything works like expected !

Any help is appreciated, thanks.

j.rebhan at

Erweitern Sie FreeMail zu einem noch lei! stungsstarkeren E-Mail-Postfach!    
Mehr Infos unter http://freemai!  

Verschicken Sie romantische, coole und witzige Bilder per SMS!   
Jetzt bei WEB.DE FreeMail: