xml-xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Waite <m...@akuma.org>
Subject Re: bug fix for XPath using Namespace
Date Fri, 18 Jun 2004 20:37:46 GMT

On Jun 18, 2004, at 12:59 PM, nn wrote:

> David,
>> The specification says 'the context of the xpath expression', but
>> doesn't define that. In XSLT, the context of an xpath expression is 
>> the
>> location within the XSLT document that it is used - all namespaces
>> declared in the element scope of the path attribute or text will
>> provide prefix mappings for the expression. In code, that context 
>> needs
>> to be given in some other manner.
>
> Do you mean that if selectPath is used to implement XSLT, it must get
> context information from the environment of the XPath? It may be a 
> possible
> case, but normally in XPath 1.0, it would be used only to access sub 
> nodes
> of target document, how other namespace outside of target document 
> would be
> relevent for it?
> Can you give me a simple example to justify such a usage?

sure, say you have a document like

<foo xmlns="urn:foo">
   <x:bar xmlns="urn:bar" id="10" />
</foo>

and

<xsl:stylesheet ... xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns="http://www.w3.org/TR/xhtml1/strict"
  xmlns:n1="urn:foo">
<html>
	<body>The value is <xsl:value-of xmlns:n2="urn:bar" 
match="/n1:foo/n2:bar@id"/>. </body>
</html>
</xsl:stylesheet>

The namespaces are in scope for the xsl:value-of by the xsl:stylesheet 
element and the value-of element itself. Because of this, the prefixes 
can be used for the xpath.  /foo/n2:bar wouldn't work (I believe) 
because the unprefixed namespace in scope is for xhtml, not urn:foo. 
/foo/x:bar won't work either (using the prefixes in the target document 
to match xpath expressions), which is a good thing - prefixes are 
pretty widely considered not to affect the content of the document.

> Anyway probably, it would be good idea to allows to use XPath in 
> various
> context.
> but the most simple case, such namespace declaration is quite 
> redendent.
> So maybe it would be useful to provide an option to use the target 
> namespace
> as implicitly declared.
>
>>
>> The odd cases are the default namespace and nonprefixed elements, I
>> can't tell you how those are supposed to work off the top of my head
>> :-)  My assumption is that nonprefixed parts of an xpath expression
>> always correspond to the default namespace of the target document; if
>> you have a non-prefixed namespace declaration on a child element, your
>> xpath needs to map that to a namespace (probably using a local prefix)
>> to match.
> this behavior would be achieved using my approach, and it seems useful.

Do people think that having a setXPathContext(...) method or methods on 
XmlOption would be appropriate? if so, the default could be 'map the 
namespace of the root element of this document to the default prefix - 
I also think this will make peoples' lives easier - most people do not 
know the.. fun-ness of namespaces and XPath :-).

-David Waite


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message