Issue using XPath in XQueries to get attributes

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue using XPath in XQueries to get attributes

Pierre Martins
Hi all,
I have trouble getting attributes in using XPath in XQueries using the APIs
 
 
_________________________________________
WHAT I WISH TO DO
 
Here is what I wish to do:
 
I want this XQuery
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return [hidden email]
To return the attribute att
 
I have tried many combinations:
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return [hidden email]
Or simply
<titi att='test'><toto att='test2'>coucou</toto></titi>/titi/@att
<titi att='test'><toto att='test2'>coucou</toto></titi>//titi/@att
 
 
_______________________________________
DESCRIPTION OF THE ISSUE
 
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()
or
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)
or
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
 
 
___________________________________
CODE
 
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 QueryAPIExample.java)

      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();
          exp.run(dynamicContext, 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
--
________________________
Pierre Martins
+33 (0) 675 190 455
[hidden email]
[hidden email]



 
Reply | Threaded
Open this post in threaded view
|

RE: Issue using XPath in XQueries to get attributes

Michael Kay
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: [hidden email] [mailto:[hidden email]] On Behalf Of Pierre Martins
Sent: 26 November 2005 16:57
To: [hidden email]
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
 
 
_________________________________________
WHAT I WISH TO DO
 
Here is what I wish to do:
 
I want this XQuery
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return [hidden email]
To return the attribute att
 
I have tried many combinations:
let $doc := (<titi att='test'><toto att='test2'>coucou</toto></titi>) return [hidden email]
Or simply
<titi att='test'><toto att='test2'>coucou</toto></titi>/titi/@att
<titi att='test'><toto att='test2'>coucou</toto></titi>//titi/@att
 
 
_______________________________________
DESCRIPTION OF THE ISSUE
 
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()
or
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)
or
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
 
 
___________________________________
CODE
 
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 QueryAPIExample.java)

      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();
          exp.run(dynamicContext, 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
--
________________________
Pierre Martins
+33 (0) 675 190 455
[hidden email]
[hidden email]



 
Reply | Threaded
Open this post in threaded view
|

evaluate()

Manuel Baehnisch
Hi,

I'm trying to add data from an external XML file (meaning other then
the one currently processed) to the result-tree.

My processed XML file looks like the following:
<root>
  <external href="name.xml" path="//foo" name="ext"/>
</root>


I would like to copy the data located in the file name.xml at the
XPath //foo into the result-tree. I do that with the following
template:

<xsl:template match="external" as="node()*">
  <xsl:variable name="doc" select="document(@href)"/>
  <xsl:variable name="path" select="@path"/>

  <xsl:element name="{@name}">
  <xsl:sequence select="saxon:evaluate($doc/$path)"/>
  </xsl:element>
</xsl:template>


Strangely, it works fine if I use it in a small test.xsl document
which only consists of this template. But once I copy it to my main
stylesheet it only produces empty output. So I suspect that my
test.xsl sort of works more "by accident".

Any help is much appreciated.
Manuel Baehnisch



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: evaluate()

Michael Kay
You want select="$doc/saxon:evaluate-node($path)"

Note: saxon:evaluate-node() uses the namespace prefixes declared in the
source document, while saxon:evaluate() uses those declared in the
stylesheet. The main point however is that $doc establishes the context for
evaluating the expression, while $path contains the expression that you want
to evaluate.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Manuel Baehnisch
> Sent: 28 November 2005 18:44
> To: [hidden email]
> Subject: [saxon] evaluate()
>
> Hi,
>
> I'm trying to add data from an external XML file (meaning other then
> the one currently processed) to the result-tree.
>
> My processed XML file looks like the following:
> <root>
>   <external href="name.xml" path="//foo" name="ext"/>
> </root>
>
>
> I would like to copy the data located in the file name.xml at the
> XPath //foo into the result-tree. I do that with the following
> template:
>
> <xsl:template match="external" as="node()*">
>   <xsl:variable name="doc" select="document(@href)"/>
>   <xsl:variable name="path" select="@path"/>
>
>   <xsl:element name="{@name}">
>   <xsl:sequence select="saxon:evaluate($doc/$path)"/>
>   </xsl:element>
> </xsl:template>
>
>
> Strangely, it works fine if I use it in a small test.xsl document
> which only consists of this template. But once I copy it to my main
> stylesheet it only produces empty output. So I suspect that my
> test.xsl sort of works more "by accident".
>
> Any help is much appreciated.
> Manuel Baehnisch
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re[2]: evaluate()

Manuel Baehnisch
Thanks.

But this is getting freaky. As long as I use my template in a
separate stylesheet it works. If I copy it too my big stylesheet the
result is empty.

So the next thing I tried is this:
...
<xsl:variable name="external" as="node()*">
<xsl:sequence select="$doc/saxon:evaluate-node($path)"/>
</xsl:variable>

<xsl:element name="test">
  <xsl:if test="not(empty($external))">
    <xsl:sequence select="$external"/>
  </xsl:if>
</xsl:element>
...

just to see, if $external is empty or not. If I fill $external as above
it is empty. But if I exchange the select with the same (but static)
content such as select="(document(@href)//foo)" it works fine.

I know its a bit much to ask but I don't want to paste the other 5k of
templates I already have. So is there any possibility that it
interfers with some other template that prevents the data to be put
into the result-tree?

Manuel Baehnisch



MK> You want select="$doc/saxon:evaluate-node($path)"

MK> Note: saxon:evaluate-node() uses the namespace prefixes declared in the
MK> source document, while saxon:evaluate() uses those declared in the
MK> stylesheet. The main point however is that $doc establishes the context for
MK> evaluating the expression, while $path contains the expression that you want
MK> to evaluate.

MK> Michael Kay
MK> http://www.saxonica.com/


>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of
>> Manuel Baehnisch
>> Sent: 28 November 2005 18:44
>> To: [hidden email]
>> Subject: [saxon] evaluate()
>>
>> Hi,
>>
>> I'm trying to add data from an external XML file (meaning other then
>> the one currently processed) to the result-tree.
>>
>> My processed XML file looks like the following:
>> <root>
>>   <external href="name.xml" path="//foo" name="ext"/>
>> </root>
>>
>>
>> I would like to copy the data located in the file name.xml at the
>> XPath //foo into the result-tree. I do that with the following
>> template:
>>
>> <xsl:template match="external" as="node()*">
>>   <xsl:variable name="doc" select="document(@href)"/>
>>   <xsl:variable name="path" select="@path"/>
>>
>>   <xsl:element name="{@name}">
>>   <xsl:sequence select="saxon:evaluate($doc/$path)"/>
>>   </xsl:element>
>> </xsl:template>
>>
>>
>> Strangely, it works fine if I use it in a small test.xsl document
>> which only consists of this template. But once I copy it to my main
>> stylesheet it only produces empty output. So I suspect that my
>> test.xsl sort of works more "by accident".
>>
>> Any help is much appreciated.
>> Manuel Baehnisch
>>
>>
>>
>> -------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc. Do you grep
>> through log files
>> for problems?  Stop!  Download the new AJAX search engine that makes
>> searching your log files as easy as surfing the  web.  
>> DOWNLOAD SPLUNK!
>> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
>> _______________________________________________
>> saxon-help mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>>




MK> -------------------------------------------------------
MK> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
MK> for problems?  Stop!  Download the new AJAX search engine that makes
MK> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
MK> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
MK> _______________________________________________
MK> saxon-help mailing list
MK> [hidden email]
MK> https://lists.sourceforge.net/lists/listinfo/saxon-help



--
Mit freundlichen GrĂ¼ssen
Manuel Baehnisch                            mailto:[hidden email]



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Re[2]: evaluate()

Michael Kay
You need to produce a complete example that demonstrates the problem. The
reason that you can't find the problem is almost certainly that you are
looking in the wrong place; you're telling me about the places where you
have looked, but I need to know about the places where you didn't look.

Incidentally, the code

>   <xsl:if test="not(empty($external))">
>     <xsl:sequence select="$external"/>
>   </xsl:if>

is equivalent to

>     <xsl:sequence select="$external"/>

Both produce () if $external is ().

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Manuel Baehnisch
> Sent: 28 November 2005 20:08
> To: [hidden email]
> Subject: Re[2]: [saxon] evaluate()
>
> Thanks.
>
> But this is getting freaky. As long as I use my template in a
> separate stylesheet it works. If I copy it too my big stylesheet the
> result is empty.
>
> So the next thing I tried is this:
> ...
> <xsl:variable name="external" as="node()*">
> <xsl:sequence select="$doc/saxon:evaluate-node($path)"/>
> </xsl:variable>
>
> <xsl:element name="test">
>   <xsl:if test="not(empty($external))">
>     <xsl:sequence select="$external"/>
>   </xsl:if>
> </xsl:element>
> ...
>
> just to see, if $external is empty or not. If I fill
> $external as above
> it is empty. But if I exchange the select with the same (but static)
> content such as select="(document(@href)//foo)" it works fine.
>
> I know its a bit much to ask but I don't want to paste the other 5k of
> templates I already have. So is there any possibility that it
> interfers with some other template that prevents the data to be put
> into the result-tree?
>
> Manuel Baehnisch
>
>
>
> MK> You want select="$doc/saxon:evaluate-node($path)"
>
> MK> Note: saxon:evaluate-node() uses the namespace prefixes
> declared in the
> MK> source document, while saxon:evaluate() uses those declared in the
> MK> stylesheet. The main point however is that $doc
> establishes the context for
> MK> evaluating the expression, while $path contains the
> expression that you want
> MK> to evaluate.
>
> MK> Michael Kay
> MK> http://www.saxonica.com/
>
>
> >> -----Original Message-----
> >> From: [hidden email]
> >> [mailto:[hidden email]] On Behalf Of
> >> Manuel Baehnisch
> >> Sent: 28 November 2005 18:44
> >> To: [hidden email]
> >> Subject: [saxon] evaluate()
> >>
> >> Hi,
> >>
> >> I'm trying to add data from an external XML file (meaning
> other then
> >> the one currently processed) to the result-tree.
> >>
> >> My processed XML file looks like the following:
> >> <root>
> >>   <external href="name.xml" path="//foo" name="ext"/>
> >> </root>
> >>
> >>
> >> I would like to copy the data located in the file name.xml at the
> >> XPath //foo into the result-tree. I do that with the following
> >> template:
> >>
> >> <xsl:template match="external" as="node()*">
> >>   <xsl:variable name="doc" select="document(@href)"/>
> >>   <xsl:variable name="path" select="@path"/>
> >>
> >>   <xsl:element name="{@name}">
> >>   <xsl:sequence select="saxon:evaluate($doc/$path)"/>
> >>   </xsl:element>
> >> </xsl:template>
> >>
> >>
> >> Strangely, it works fine if I use it in a small test.xsl document
> >> which only consists of this template. But once I copy it to my main
> >> stylesheet it only produces empty output. So I suspect that my
> >> test.xsl sort of works more "by accident".
> >>
> >> Any help is much appreciated.
> >> Manuel Baehnisch
> >>
> >>
> >>
> >> -------------------------------------------------------
> >> This SF.net email is sponsored by: Splunk Inc. Do you grep
> >> through log files
> >> for problems?  Stop!  Download the new AJAX search engine
> that makes
> >> searching your log files as easy as surfing the  web.  
> >> DOWNLOAD SPLUNK!
> >> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> >> _______________________________________________
> >> saxon-help mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/saxon-help
> >>
>
>
>
>
> MK> -------------------------------------------------------
> MK> This SF.net email is sponsored by: Splunk Inc. Do you
> grep through log files
> MK> for problems?  Stop!  Download the new AJAX search engine
> that makes
> MK> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> MK> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> MK> _______________________________________________
> MK> saxon-help mailing list
> MK> [hidden email]
> MK> https://lists.sourceforge.net/lists/listinfo/saxon-help
>
>
>
> --
> Mit freundlichen GrĂ¼ssen
> Manuel Baehnisch                            
> mailto:[hidden email]
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> <a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=ick">http://ads.osdn.com/?ad_idv37&alloc_id865&op=ick
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
<a href="http://ads.osdn.com/?ad_idv37&alloc_id865&op=click">http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re[4]: evaluate()

Manuel Baehnisch
I just managed to reproduce it in a small stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
     xmlns:saxon="http://saxon.sf.net/"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
     xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes" >
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template name="external" as="node()*">
  <xsl:param name="node" as="node()" required="yes"/>
 
  <xsl:variable name="doc" select="document($node/@href)"/>
  <xsl:variable name="path" select="$node/@path"/>

  <xsl:variable name="data" as="node()*">
<!--   here  -->
  <xsl:sequence select="$doc/saxon:evaluate-node($path)"/>
  </xsl:variable>
 
  <xsl:element name="test">
    <xsl:sequence select="$data"/>
  </xsl:element>
 
</xsl:template>  
 
 
<xsl:template match="Extern">
  <xsl:call-template name="external">
    <xsl:with-param name="node" select="."/>
  </xsl:call-template>
</xsl:template>

</xsl:stylesheet>


The source.xml looks like
<root>
  <Extern href="Test.xml" path="//foo"/>
</root>


while Test.xml is
<A>
  <foo> some <b> bold </b> text </foo>
</A>



Now if I interchange select="$doc/saxon:evaluate-node($path)" with the
static select="$doc//foo" the output is not just <test/> but
<test>
  <foo> some <b> bold </b> text </foo>
</test>

What am I doing wrong?

Thanks allot.
Manuel Baehnisch







-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Re[4]: evaluate()

Michael Kay
Sorry, my advice to use saxon:evaluate-node() was wrong. As well as taking
the namespace context from the source document, this function also evaluates
the path expression relative to the element node containing the expression.
If you use saxon:evaluate() rather than saxon:evaluate-node(), the
stylesheet works OK.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Manuel Baehnisch
> Sent: 28 November 2005 21:04
> To: Michael Kay
> Subject: Re[4]: [saxon] evaluate()
>
> I just managed to reproduce it in a small stylesheet:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
>      xmlns:saxon="http://saxon.sf.net/"
>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>      xmlns:xs="http://www.w3.org/2001/XMLSchema"
>      xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
>      xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes" >
>   <xsl:output method="xml" version="1.0" encoding="UTF-8"
> indent="yes"/>
>
> <xsl:template name="external" as="node()*">
>   <xsl:param name="node" as="node()" required="yes"/>
>  
>   <xsl:variable name="doc" select="document($node/@href)"/>
>   <xsl:variable name="path" select="$node/@path"/>
>
>   <xsl:variable name="data" as="node()*">
> <!--   here  -->
>   <xsl:sequence select="$doc/saxon:evaluate-node($path)"/>
>   </xsl:variable>
>  
>   <xsl:element name="test">
>     <xsl:sequence select="$data"/>
>   </xsl:element>
>  
> </xsl:template>  
>  
>  
> <xsl:template match="Extern">
>   <xsl:call-template name="external">
>     <xsl:with-param name="node" select="."/>
>   </xsl:call-template>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> The source.xml looks like
> <root>
>   <Extern href="Test.xml" path="//foo"/>
> </root>
>
>
> while Test.xml is
> <A>
>   <foo> some <b> bold </b> text </foo>
> </A>
>
>
>
> Now if I interchange select="$doc/saxon:evaluate-node($path)" with the
> static select="$doc//foo" the output is not just <test/> but
> <test>
>   <foo> some <b> bold </b> text </foo>
> </test>
>
> What am I doing wrong?
>
> Thanks allot.
> Manuel Baehnisch
>
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re[6]: evaluate()

Manuel Baehnisch
No problem, ... but, I should mention I'm fairly new to this. So, how do I
have change the select-statement then? Because neither
select="$doc/saxon:evaluate($path)" nor
select="saxon:evaluate($doc/$path)" work as expected. Sorry to
bother...

Manuel Baehnisch

MK> Sorry, my advice to use saxon:evaluate-node() was wrong. As well as taking
MK> the namespace context from the source document, this function also evaluates
MK> the path expression relative to the element node containing the expression.
MK> If you use saxon:evaluate() rather than saxon:evaluate-node(), the
MK> stylesheet works OK.

MK> Michael Kay
MK> http://www.saxonica.com/ 

>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of
>> Manuel Baehnisch
>> Sent: 28 November 2005 21:04
>> To: Michael Kay
>> Subject: Re[4]: [saxon] evaluate()
>>
>> I just managed to reproduce it in a small stylesheet:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xsl:stylesheet version="2.0"
>>      xmlns:saxon="http://saxon.sf.net/"
>>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>      xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>      xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
>>      xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes" >
>>   <xsl:output method="xml" version="1.0" encoding="UTF-8"
>> indent="yes"/>
>>
>> <xsl:template name="external" as="node()*">
>>   <xsl:param name="node" as="node()" required="yes"/>
>>  
>>   <xsl:variable name="doc" select="document($node/@href)"/>
>>   <xsl:variable name="path" select="$node/@path"/>
>>
>>   <xsl:variable name="data" as="node()*">
>> <!--   here  -->
>>   <xsl:sequence select="$doc/saxon:evaluate-node($path)"/>
>>   </xsl:variable>
>>  
>>   <xsl:element name="test">
>>     <xsl:sequence select="$data"/>
>>   </xsl:element>
>>  
>> </xsl:template>  
>>  
>>  
>> <xsl:template match="Extern">
>>   <xsl:call-template name="external">
>>     <xsl:with-param name="node" select="."/>
>>   </xsl:call-template>
>> </xsl:template>
>>
>> </xsl:stylesheet>
>>
>>
>> The source.xml looks like
>> <root>
>>   <Extern href="Test.xml" path="//foo"/>
>> </root>
>>
>>
>> while Test.xml is
>> <A>
>>   <foo> some <b> bold </b> text </foo>
>> </A>
>>
>>
>>
>> Now if I interchange select="$doc/saxon:evaluate-node($path)" with the
>> static select="$doc//foo" the output is not just <test/> but
>> <test>
>>   <foo> some <b> bold </b> text </foo>
>> </test>
>>
>> What am I doing wrong?
>>
>> Thanks allot.
>> Manuel Baehnisch
>>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re[7]: evaluate()

Manuel Baehnisch
MB> No problem, ... but, I should mention I'm fairly new to this. So, how do I
MB> have change the select-statement then? Because neither
MB> select="$doc/saxon:evaluate($path)" nor
MB> select="saxon:evaluate($doc/$path)" work as expected. Sorry to
MB> bother...


Ahh. My mistake. Works perfectly now. Thanks allot.

Manuel Baehnisch



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Re[6]: evaluate()

Michael Kay
In reply to this post by Manuel Baehnisch
This is the stylesheet as I ran it:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
     xmlns:saxon="http://saxon.sf.net/"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema"
     xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
     xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes" >
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template name="external" as="node()*">
  <xsl:param name="node" as="node()" required="yes"/>
 
  <xsl:variable name="doc" select="document($node/@href)"/>
  <xsl:variable name="path" select="$node/@path"/>
 
  <xsl:message select="$doc">[doc]</xsl:message>
  <xsl:message select="$path">[path]</xsl:message>

  <xsl:variable name="data" as="node()*">
<!--   here  -->
  <xsl:sequence select="$doc/saxon:evaluate($path)"/>
  </xsl:variable>
 
  <xsl:element name="test">
    <xsl:sequence select="$data"/>
  </xsl:element>
 
</xsl:template>  
 
 
<xsl:template match="Extern">
  <xsl:call-template name="external">
    <xsl:with-param name="node" select="."/>
  </xsl:call-template>
</xsl:template>

</xsl:stylesheet>

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> Manuel Baehnisch
> Sent: 28 November 2005 21:42
> To: [hidden email]
> Subject: Re[6]: [saxon] evaluate()
>
> No problem, ... but, I should mention I'm fairly new to this.
> So, how do I
> have change the select-statement then? Because neither
> select="$doc/saxon:evaluate($path)" nor
> select="saxon:evaluate($doc/$path)" work as expected. Sorry to
> bother...
>
> Manuel Baehnisch
>
> MK> Sorry, my advice to use saxon:evaluate-node() was wrong.
> As well as taking
> MK> the namespace context from the source document, this
> function also evaluates
> MK> the path expression relative to the element node
> containing the expression.
> MK> If you use saxon:evaluate() rather than saxon:evaluate-node(), the
> MK> stylesheet works OK.
>
> MK> Michael Kay
> MK> http://www.saxonica.com/ 
>
> >> -----Original Message-----
> >> From: [hidden email]
> >> [mailto:[hidden email]] On Behalf Of
> >> Manuel Baehnisch
> >> Sent: 28 November 2005 21:04
> >> To: Michael Kay
> >> Subject: Re[4]: [saxon] evaluate()
> >>
> >> I just managed to reproduce it in a small stylesheet:
> >>
> >> <?xml version="1.0" encoding="UTF-8"?>
> >> <xsl:stylesheet version="2.0"
> >>      xmlns:saxon="http://saxon.sf.net/"
> >>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >>      xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >>      xmlns:fn="http://www.w3.org/2004/07/xpath-functions"
> >>      xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes" >
> >>   <xsl:output method="xml" version="1.0" encoding="UTF-8"
> >> indent="yes"/>
> >>
> >> <xsl:template name="external" as="node()*">
> >>   <xsl:param name="node" as="node()" required="yes"/>
> >>  
> >>   <xsl:variable name="doc" select="document($node/@href)"/>
> >>   <xsl:variable name="path" select="$node/@path"/>
> >>
> >>   <xsl:variable name="data" as="node()*">
> >> <!--   here  -->
> >>   <xsl:sequence select="$doc/saxon:evaluate-node($path)"/>
> >>   </xsl:variable>
> >>  
> >>   <xsl:element name="test">
> >>     <xsl:sequence select="$data"/>
> >>   </xsl:element>
> >>  
> >> </xsl:template>  
> >>  
> >>  
> >> <xsl:template match="Extern">
> >>   <xsl:call-template name="external">
> >>     <xsl:with-param name="node" select="."/>
> >>   </xsl:call-template>
> >> </xsl:template>
> >>
> >> </xsl:stylesheet>
> >>
> >>
> >> The source.xml looks like
> >> <root>
> >>   <Extern href="Test.xml" path="//foo"/>
> >> </root>
> >>
> >>
> >> while Test.xml is
> >> <A>
> >>   <foo> some <b> bold </b> text </foo>
> >> </A>
> >>
> >>
> >>
> >> Now if I interchange
> select="$doc/saxon:evaluate-node($path)" with the
> >> static select="$doc//foo" the output is not just <test/> but
> >> <test>
> >>   <foo> some <b> bold </b> text </foo>
> >> </test>
> >>
> >> What am I doing wrong?
> >>
> >> Thanks allot.
> >> Manuel Baehnisch
> >>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help