W3C home > Mailing lists > Public > xproc-dev@w3.org > October 2011

RE: Namespace problems in XPath expression with label attribute

From: <vojtech.toman@emc.com>
Date: Mon, 24 Oct 2011 05:35:45 -0400
To: <xproc-dev@w3.org>
Message-ID: <3799D0FD120AD940B731A37E36DAF3FE33E1D5B0BD@MX20A.corp.emc.com>
Georges,

I think that your example with p:label-elements should work:

<p:label-elements match="ns2:rating-entry" attribute="synchro-id" 
label="string-join(('eap-145',parent::ns2:rating-entry/ns2:code,ns2:code),'-')" 
replace="true" name="init-synchro-id"/>

That Calabash gives you an error is, I believe, a bug in Calabash.

In Calumet it works. However, you mentioned in your last email that it does returns "no result for elements with 'ns2' prefix". Can you elaborate? I tested against the following document:

<ns2:rating-entry xmlns:ns2="http://www.empic.aero/ns/empic-eap/oas">
  <ns2:rating-entry>
    <ns2:code>cd1</ns2:code>
  </ns2:rating-entry>
  <ns2:code>cd2</ns2:code>
</ns2:rating-entry> 

The step finds two ns2:rating-entry elements. For the first match (the top-level one), the label expression produces "eap-145-cd2", for the second one, it produces "eap-145-cd2-cd1"


Now the reasons why the step should work:

First, the XPath expression that is the value of the "label" option is executed using the Step XPath context. (If you look into the specification you will find also the Processor XPath context there - the main difference is that when you use an XPath expression to construct a value for an option (for example, by using p:with-option), then this expression is evaluated by the processor. But when a step treats the value of a specific value as an XPath expression (for example, the "label" option of p:label-elements), then this XPath expression is executed by the step.)

The in-scope namespaces in the Step XPath context are defined as follows:

"
The set of namespace bindings provided by the XProc processor. The processor computes this set of bindings by taking a union of the bindings on the step element itself as well as the bindings on any of the options and parameters used in computing values for the step (see Section 5.7.5, "Namespaces on variables, options, and parameters").
"

So, this means that the namespace bindings for ns2 *must* be available when the p:label-elements evaluates the label XPath expression. 

I also noticed that this situation is not tested in the XProc test suite, so I think I should add a test.


Regards,
Vojtech

--
Vojtech Toman
Consultant Software Engineer
EMC | Information Intelligence Group
vojtech.toman@emc.com
http://developer.emc.com/xmltech

> -----Original Message-----
> From: xproc-dev-request@w3.org [mailto:xproc-dev-request@w3.org] On
> Behalf Of Georges Schmitz
> Sent: Sunday, October 23, 2011 10:48 PM
> To: xproc-dev@w3.org
> Subject: Re: Namespace problems in XPath expression with label
> attribute
> 
> Hi,
> 
> I tried more or less a similar thing with *calumet*, I get
> 
> a) no error message but
> b) also no result for elements with "ns2" prefix as shown under point
> C)
> below.
> 
> Any hint appreciated. Point me to some documentation, if it is just a
> question of not knowing all the details.
> 
> Georges
> 
> Am 13.10.2011 14:37, schrieb Georges Schmitz:
> > Hi All,
> >
> > I can't get namespaces working in the XPath expression of the label
> > attribute in p:label-elements.
> >
> > What I did and also worked:
> >
> > A) Declaration of namespace for the step:
> >
> > <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
> > xmlns:ns2="http://www.empic.aero/ns/empic-eap/oas"
> >     version="1.0" name="clean-up-ratings">
> >
> > B) Using the namespace in match pattern
> >
> > <p:delete match="ns2:*[@lang and not(@lang='en')]" name="clean-up-
> lang"/>
> >
> > C) Using string functions in the XPath expression of the label
> > attribute, accessing parent and child elements of the current
> node,...
> >
> > <p:label-elements match="ns2:rating-entry" attribute="synchro-id"
> > label="string-join(('eap-145',parent::*:rating-
> entry/*:code,*:code),'-')"
> > replace="true" name="init-synchro-id"/>
> >
> > This already produces the desired result, but you can imagine that
> I'm
> > not happy with it. I did it just this way round to check for other
> > obvious mistakes.
> >
> > Because the following doesn't work:
> >
> > <p:label-elements match="ns2:rating-entry" attribute="synchro-id"
> > label="string-join(('eap-145',parent::ns2:rating-
> entry/ns2:code,ns2:code),'-')"
> > replace="true" name="init-synchro-id"/>
> >
> > Apparently saxon doesn't see the namespace declaration I made under
> > (A), I get the following error message:
> >
> >   Underlying exception: net.sf.saxon.s9api.SaxonApiException: Prefix
> > ns2 has not been declared
> >
> > Any extra declaration of the namespace needed (where and how?) or
> just
> > a bug? I'm using calabash 0.9.36 (same problem with 0.9.32).
> >
> > Thanks for clarification,
> > Georges
> >
> >
> 
> 
Received on Monday, 24 October 2011 09:36:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 24 October 2011 09:36:43 GMT