Re: string-replace match="Date/text()" replace="Title/text()" not doing what I would have thought.. why?

On Thu, Nov 12, 2009 at 1:19 AM, Leif Warner <abimelech@gmail.com> wrote:

> In the "replace" attribute, the current XPath context at that time is the
> "Date/text()" node, you can see this by putting "replace='name(..)'".
> If you want to reference the title text from there, you could say
> "replace='../../Title'", "/Book/Title", or "//Title".  Basically, either go
> up a couple levels to get to the Title, or start at the iteration source
> root to get to the title.  Does that make sense?
>

Hi yes I understand the context aspect now. It seemed more intuitive to me
that the context was supplied by    <p:iteration-source select="//Book" />
given that it supplies the initial context to the match.



>
> Also, in this case, the for-each followed by wrap-sequence might be better
> expressed as a viewport.  It will just apply a process to a list of
> sub-elements in the document, without splitting it into chunks to be
> re-stitched together.  It's much like the "map" function in functional-style
> programing as opposed to the imperative-style "for-each".  I'm unaware of
> the rationale behind naming it "viewport".
>

Thanks I'll check around for a viewport example.
Alex


>
> -Leif Warner
>
>
> On Wed, Nov 11, 2009 at 7:43 AM, Alex Muir <alex.g.muir@gmail.com> wrote:
>
>> Hi,
>>
>> I'm just playing with an example of from a great tutorial by Roger
>> Costello and James Garriss using Calabash and getting a result I don't
>> understand.
>>
>> Given this xproc:
>>
>> <p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
>>                 xmlns:c="http://www.w3.org/ns/xproc-step"
>>                 name="myPipeline">
>>
>>     <p:input port="source">
>>         <p:document href="BookStore.xml"/>
>>     </p:input>
>>
>>     <p:output port="result" />
>>
>>     <p:for-each>
>>         <p:iteration-source select="//Book" />
>>         <p:string-replace match="Date/text()" replace="Title/text()" />
>>     </p:for-each>
>>     <p:wrap-sequence wrapper="BookStore" />
>>
>> </p:declare-step>
>>
>>
>> And this XML:
>>
>> <?xml version="1.0"?>
>> <BookStore>
>>     <Book>
>>         <Title>My Life and Times</Title>
>>         <Author>Paul McCartney</Author>
>>         <Date>1998</Date>
>>         <ISBN>1-56592-235-2</ISBN>
>>         <Publisher>McMillin Publishing</Publisher>
>>     </Book>
>>     <Book>
>>         <Title>Illusions The Adventures of a Reluctant Messiah</Title>
>>         <Author>Richard Bach</Author>
>>         <Date>1977</Date>
>>         <ISBN>0-440-34319-4</ISBN>
>>         <Publisher>Dell Publishing Co.</Publisher>
>>     </Book>
>>     <Book>
>>         <Title>The First and Last Freedom</Title>
>>         <Author>J. Krishnamurti</Author>
>>         <Date>1954</Date>
>>         <ISBN>0-06-064831-7</ISBN>
>>         <Publisher>Harper &amp; Row</Publisher>
>>     </Book>
>> </BookStore>
>>
>> I'm getting output
>>
>> <BookStore>
>>     <Book>
>>         <Title>My Life and Times</Title>
>>         <Author>Paul McCartney</Author>
>>         <Date/>
>>         <ISBN>1-56592-235-2</ISBN>
>>         <Publisher>McMillin Publishing</Publisher>
>>     </Book>
>>     <Book>
>>         <Title>Illusions The Adventures of a Reluctant Messiah</Title>
>>         <Author>Richard Bach</Author>
>>         <Date/>
>>         <ISBN>0-440-34319-4</ISBN>
>>         <Publisher>Dell Publishing Co.</Publisher>
>>     </Book>
>>     <Book>
>>         <Title>The First and Last Freedom</Title>
>>         <Author>J. Krishnamurti</Author>
>>         <Date/>
>>         <ISBN>0-06-064831-7</ISBN>
>>         <Publisher>Harper &amp; Row</Publisher>
>>     </Book>
>> </BookStore>
>>
>> I would have thought I would get a <Date> tag with some title text()
>> however I'm getting the empty <Date/> tags?
>>
>> Why is that and how can I move the title text into the date element as I'm
>> trying to do.
>>
>>
>> Thanks Much
>>
>> --
>>
>>
>> Alex
>> https://sites.google..com/a/utg.edu.gm/alex<https://sites.google.com/a/utg.edu.gm/alex>
>>
>>
>


-- 

Alex
https://sites.google.com/a/utg.edu.gm/alex

Received on Thursday, 12 November 2009 11:37:36 UTC