Re: p:split-sequence gives "Undeclared variable in XPath expression"

Ah, of course! I knew it had to have a simple explaination but my brain got
stuck. Thanks all :)

Jostein

2011/8/16 <vojtech.toman@emc.com>

> That is because in this case, the p:split-sequence **step** evaluates the
> “test” XPath expression, not the processor. (This is similar to, for
> instance, to the p:string-replace step). In the step XPath context (see
> 2.6.1.2 Step XPath Context in the XProc specification), the variable
> bindings are empty.****
>
> ** **
>
> The problem is that the value of the “test” option that the step gets is
> “$option” and not “true()”. The value is just a string that the step then
> interprets as an XPath expression. So, to make your example work, you should
> do the following (note the apostrophes around true() – they are important,
> as I will explain below):****
>
> ** **
>
> <p:option name="option" select="'true()'"/>****
>
> ** **
>
> <p:split-sequence>****
>
>   <p:with-option name=”test” select=”$option”/>****
>
> </p:split-sequence>****
>
> ** **
>
> What this does is that because the long-form p:with-option is used, the
> processor first evaluates the p:with-option/@select expression (using the
> processor step context in which $option can be resolved) and passes the
> result (the string ”true()” – the quotes are not part of the string) to the
> p:split-sequence step – which then evaluates it as an XPath expression using
> the step XPath context.****
>
> ** **
>
> Now about the apostrophes around true() in the declaration of the “option”
> option. They make sure that the value of the option is a string “true()” and
> not just “true” (quotes not part of the strings). The former is an XPath
> expression that results in boolean TRUE, whereas the latter is an XPath
> expression that is a node test (for the element named “true”). Therefore
> what you want to pass as the value for the “test” option of p:split-sequence
> is “true()”.****
>
> ** **
>
> Hope this helps.****
>
> ** **
>
> Regards,****
>
> Vojtech****
>
> ** **
>
> --****
>
> Vojtech Toman****
>
> Consultant Software Engineer****
>
> EMC | Information Intelligence Group****
>
> vojtech.toman@emc.com****
>
> http://developer.emc.com/xmltech****
>
> ** **
>
> *From:* xproc-dev-request@w3.org [mailto:xproc-dev-request@w3.org] *On
> Behalf Of *Jostein Austvik Jacobsen
> *Sent:* Tuesday, August 16, 2011 3:52 PM
> *To:* XProc Dev
> *Subject:* p:split-sequence gives "Undeclared variable in XPath
> expression"****
>
> ** **
>
> Hi all.****
>
> ** **
>
> I'm always excited when I come across a use-case that lets me use an XProc
> step that I haven't used before, and today I tried p:split-sequence. It
> seemed pretty straight forward, however I stumbled upon a problem right
> away. This pipeline doesn't work:****
>
> ** **
>
> ** **
>
> <?xml version="1.0" encoding="UTF-8"?>****
>
> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="1.0">****
>
> ** **
>
>     <p:input port="source" sequence="true">****
>
>         <p:inline>****
>
>             <doc/>****
>
>         </p:inline>****
>
>     </p:input>****
>
>     <p:output port="result" sequence="true"/>****
>
>     <p:option name="option" select="true()"/>****
>
>     ****
>
>     <p:split-sequence test="$option"/>****
>
> ** **
>
> </p:declare-step>****
>
> ** **
>
> ** **
>
> This fails with the message "*Undeclared variable in XPath expression:
> $option*". If I replace *test="$option"* with either *test="true()"* or *
> test="position()=1"* it works. But when I introduce a variable or option
> into the test, it fails. So what am I missing here?****
>
> ** **
>
> ** **
>
> Regards****
>
> Jostein****
>

Received on Tuesday, 16 August 2011 15:50:01 UTC