RE: Puzzled about options

> Hi Folks,
> 
> Consider the following examples which show the use of the 
> "select" and "href" options.
> 
> 
> OPTIONS USED AS ATTRIBUTES

There is a difference between specifying the options as attributes (also
called 'the shortcut form') and as child elements (using p:with-option).

When you use the shortcut form, the value is taken as is, as a simple
constant string. If you use <p:with-option name="..." select="...">, the
value of the p:with-option/@select attribute is interpreted (and
evaluated) as an XPath expression, and the option will be assigned the
result of evaluating this expression. See section 4.8.1 of the
specification.

This is why:

<p:store href="/Book/Filename"/>

will use the '/Book/Filename' string value as the value of the 'href'
option. And because p:store interprets 'href' as an URI, it will attempt
to store the document to URI "/Book/Filename" - which is probably not
what you want.

However,

<p:store>
  <p:with-option name="href" select="/Book/Filename"/>
</p:store>

will apply the '/Book/Filename' XPath expression on the current context
first, and then use this as the value for the 'href' option.

--

This works the same for all steps, although for some of them - such as
p:filter - it may be more confusing, since they interpret some of the
options as XPath expressions (for instance, the 'select' option of
p:filter):

<p:filter select="/BookStore/Book[Date=1998]"/>

will take the '/BookStore/Book[Date=1998]' string value and assign it
(as is, as a constant) to the 'select' option. The step then takes this
value and evaluates it as an XPath expression when processing the input
document.

To make it more interesting,

<p:filter>
  <p:with-option name="select" 
    select="/BookStore/Book[Date=1998]"  />
</p:filter>

will first evaluate the '/BookStore/Book[Date=1998]' XPath expression to
get the value for the 'select' option. The step then takes this value
and evaluates it as an XPath expression again. So, in this case, you
have an XPath expression that should evaluate to another XPath
expression...


Regards,
Vojtech

Received on Monday, 26 January 2009 07:44:54 UTC