- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Sat, 20 Sep 2008 20:00:20 +0100
- To: James Garriss <james@garriss.org>
- Cc: XProc Dev <xproc-dev@w3.org>
James,
On 19 Sep 2008, at 23:04, James Garriss wrote:
> Suppose I wanted to wrap the two <Book> elements with a <Books>
> element, so it would look like this:
>
> <BookStore>
> <Books>
> <Book>...
> <Book>...
> </Books>
> <Invoice>
> <Cost>...
> </Invoice>
> </BookStore>
>
> I should have thought one of these would have worked:
>
> <p:wrap wrapper="Books" match="//Book" group-
> adjacent="boolean(self::Book)"/>
> <p:wrap wrapper="Books" match="//Book" group-adjacent=". instance of
> element(Book)"/>
Actually, given the way p:wrap is written, I think that:
<p:wrap wrapper="Books" match="Book" group-adjacent="true()" />
should work. The only things you want to wrap are <Book> elements, and
whenever there are any of them in a sequence, you want to wrap them
together; the XPath expression "true()" always returns true.
The expression boolean(self::Book) would work as well, but would be
better for a situation such as:
<Section>
<Text>...</Text>
<Text>...</Text>
<Item>...</Item>
<Item>...</Item>
<Text>...</Text>
</Section>
where you could do:
<p:wrap wrapper="Para" match="Section/*" group-
adjacent="boolean(self::Item)" />
which would wrap all the elements within <Section> in <Para> elements,
and wrap the <Item> elements together, like so:
<Section>
<Para><Text>...</Text></Para>
<Para><Text>...</Text></Para>
<Para>
<Item>...</Item>
<Item>...</Item>
</Para>
<Para><Text>...</Text></Para>
</Section>
(You'd then want a step that turned the Para elements that held Item
elements into List elements, like: <p:rename match="Para[Item]" new-
name="List" />.)
Jeni
--
Jeni Tennison
http://www.jenitennison.com
Received on Saturday, 20 September 2008 19:00:55 UTC