Re: Calabash string-replace problem

Gerrit, thanks.

Lessons learned:

1. xproc is not xslt
2. p:with-option is not the same as xsl:with-param

I'll be spending more time in the XPath spec.

Regards,
--Paul

On Thu, 2013-11-14 at 22:50 +0100, Imsieke, Gerrit, le-tex wrote:
> see below
> 
> On 14.11.2013 21:30, Paul Tyson wrote:
> > I must be missing something very simple, but I have tried everything I
> > can think of. Thanks in advance for any assistance.
> >
> > Here is the problem reduced to a simple pipeline.
> >
> > <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
> >
> >                                  xmlns:html="http://www.w3.org/1999/xhtml"
> >
> >                                  version="1.0">
> >
> >    <p:output port="result"/>
> >
> >    <p:option name="pn" select="'foo'"/>
> >
> >    <p:string-replace match="//html:span/text()">
> >
> >      <p:input port="source">
> >
> >        <p:inline>
> >
> >                  <html:div>Part number <html:span
> > style="font-weight:bold;font-size:larger">aaa</html:span> not
> > found.</html:div>
> >
> >        </p:inline>
> >
> >      </p:input>
> >
> >      <p:with-option name="replace" select="$pn"/>
> 
> $pn will be evaluated here and expand to the string 'foo' without the 
> single quotes. The situation is as if you specified
> 
> <p:string-replace match="//html:span/text()" replace="foo">
> 
> in first place, where foo will be evaluated in the context of the 
> document on the source port.
> 
> Try the following expression:
> 
> <p:with-option name="replace" select="concat('''', $pn, '''')"/>
> 
> This will calculate the value of the replace option to be 'foo'.
> 
> The inner '' pairs are just escapes for a single quote, which has to be 
> wrapped in single quotes in order to be part of a string. So you’re 
> concatenating the string ', the string foo, and the string ' to form the 
> string 'foo'.
> 
> This string is then supplied as the XPath expression for the replace 
> option. When evaluated, it yields the string foo.
> 
> I hope this becomes clear. When specifying replace using p:with-option, 
> you construct an XPath expression using XPath expressions.
> 
> There is no more direct way to evaluate $pn (for example, in 
> replace="$pn") because the variable is not bound in the context of the 
> source document.
> 
> Just play around with it and see what happens:
> 
> <p:with-option name="replace" select="'//*[local-name()=''span'']/@style'"/>
> 
> ⇒ font-weight:bold;font-size:larger
> 
> <p:with-option name="replace" 
> select="concat('//*[string-length(local-name(.)) gt string-length(''', 
> $pn, ''')]/name()')"/>
> 
> ⇒ html:span
> 
> Silly me, I first tried the expression
> 
> <p:with-option name="replace" 
> select="concat('//*[string-length(local-name(.)) gt string-length(', 
> $pn, ')]/name()')"/>
> 
> and got html:divhtml:span as a result. If you know why, you’ll have 
> grokked it.
> 
> Gerrit
> 

Received on Friday, 15 November 2013 23:57:15 UTC