It's better to use the xquery-talk list or the xsl-list for general XQuery/XPath questions that are not specifically Saxon-related.
The value of $doc, despite its name, is not a document node but an element node (whose name is titi). $doc//titi selects all the descendants of that titi element named titi, and there are none. $doc/titi selects all the titi children of that titi element, and again there are none.
You may find it less confusing if you create temporary trees with a containing document node, as
let $doc := document { <titi>....</titi> }
If you want to get errors when you use an incorrect path expression, rather than just returning an empty sequence, you will need to have a schema for the document structure, and to validate the document against the schema. Saxon-SA will then give you compile-time warnings when you use path expressions that can't be satisfied by the imported schema.
Michael Kay

From: [] On Behalf Of Pierre Martins
Sent: 26 November 2005 16:57
Subject: [Norton AntiSpam] [saxon] Issue using XPath in XQueries to get attributes

Hi all,
I have trouble getting attributes in using XPath in XQueries using the APIs
Here is what I wish to do:
I want this XQuery
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc//titi/@att
To return the attribute att
I have tried many combinations:
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc/titi/@att
Or simply
<titi att='test'><toto att='test2'>coucou</toto></titi>/titi/@att
<titi att='test'><toto att='test2'>coucou</toto></titi>//titi/@att
1) I don't have any error displayed
2) No results are returned
I have another strange behaviour with element's item:
If I do
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc//toto/text()
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc/toto/text()
I have the result 'coucou'
BUT if I do:
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc/titi/toto/text() (Well I know that If we consider the standars, this one shouldn't work anyway)
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return $doc//titi/toto/text() (Should be ok)
I have the same behaviour as for the attribute issue except I have the turnaround
I am using the following code (where 'test' is the String containing the XQuery):
(This is very similar to the method 'exampleToStreamResult()' in the example file

      String result = new String();

      try {
          final Configuration config = new Configuration();
          final StaticQueryContext sqc = new StaticQueryContext(config);
          final XQueryExpression exp = sqc.compileQuery(test);
          Properties props = new Properties();

          final DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
          props.setProperty(OutputKeys.METHOD, "xml");
          props.setProperty(OutputKeys.INDENT, "no");
          ByteArrayOutputStream theTest = new ByteArrayOutputStream();
, new StreamResult(theTest), props);
          result = theTest.toString();
          result = Utils.removeXmlHeader(result);
          //log.getLogger().debug("THE RESULT ========>" + result + "_");
          System.out.println("THE RESULT ========>" + result + "_");
      } catch (XPathException e){
       //log.getLogger().error("Not able to process XQuery expression due to XPath exception =>" + e.getMessage());
       System.out.println("Not able to process XQuery expression due to XPath exception =>" + e.getMessage());

Am I doing something wrong ?

Pierre Martins
+33 (0) 675 190 455