Venkat, I made a couple of points below.  Send me the stylesheet and I'll 
look through it if you want.  The complication for your second question is 
that in XPath/XSLT 1.0, some instructions work with the first node in a 
nodeset, while others iterate through the whole nodeset.

Cheers, 
-Doug



From:
"Venkata Krishnan" <[EMAIL PROTECTED]>
To:
tuscany-dev <[email protected]>
Date:
02/08/2008 07:23 AM
Subject:
XPath related question



Hi,

I am trying to get some xpaths evaluated against a composite file.  I have 
a
couple of questions related to xpath queries.  Can somebody familiar 
please
help.   Thanks.

My composite element in the composite file defines the defaultnamespace -
xmlns="http://www.osoa.org/xmlns/sca/1.0";.  Given this if I construct a
xpath that is like "/composite" or "/composite/component" the query does 
not
return any result.

* If you're using XPath/XSLT 1.0, you have to use the namespace inside the 

* XPath expression.  If you have the option to move to XPath/XSLT 2.0 
(depends
* on your application), XSLT 2.0 adds the xpath-default-namespace 
attribute to
* <xsl:stylesheet>. 

On the other hand if I added the following namespace declaration to the
composite element "xmlns*:sca*="http://www.osoa.org/xmlns/sca/1.0"; and 
then
constructed an xpath - "/sca:composite" or "/sca:composite/sca:component",
then the query returns the expected results.  Any clues to what I am 
missing
out here ?

* This is what you have to do for XPath/XSLT 1.0.  If a node is namespace-
* qualified in the XML document, it has to be namespace-qualified in the 
XPath
* expression as well.  If you move to 2.0, you can do this:

* <xsl:stylesheet version="2.0" 
*  ...
*  xpath-default-namespace="http://www.osoa.org/xmlns/sca/1.0";
*  xmlns:sca="http://www.osoa.org/xmlns/sca/1.0";>
* . . .
*   <xsl:template match="/composite/component">

* The xpath-default-namespace attribute tells XPath to assume every 
element
* is qualified with the default namespace.

The other question I have is, to an xpath - "/sca:composite/sca:component" 
I
expect the set of all component nodes to be returned, but instead I seem 
to
be getting just the first one.  How do I get the set of all component 
nodes
?

* This depends on how your stylesheet is set up.  In XPath/XSLT 1.0, the 
* stylesheet processor uses the first node of a nodeset in many cases.
* (This can get complicated and causes errors when you move to XSLT 2.0.)
* If you do something like this:

*    <xsl:for-each select="/sca:composite/sca:component">

* The stylesheet will iterate through all of the nodes matched by the 
XPath
* expression.  On the other hand, this expression only works with the 
first
* node in the nodeset:

*    <xsl:value-of select="/sca:composite/sca:component"/>

Thanks

- Venkat

Reply via email to