W3C home > Mailing lists > Public > xproc-dev@w3.org > November 2009

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

From: Leif Warner <abimelech@gmail.com>
Date: Wed, 11 Nov 2009 17:19:50 -0800
Message-ID: <54d4ec0f0911111719m1f2e760fk212966313a96cb62@mail.gmail.com>
To: Alex Muir <alex.g.muir@gmail.com>
Cc: xproc-dev@w3.org
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?

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".

-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>
>
>
Received on Thursday, 12 November 2009 01:20:33 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 12 November 2009 01:20:34 GMT