- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Thu, 18 Sep 2008 22:00:29 +0100
- To: James Garriss <james@garriss.org>
- Cc: XProc Dev <xproc-dev@w3.org>
Hi James,
On 18 Sep 2008, at 21:45, James Garriss wrote:
> The p:wrap step has a group-adjacent option. I understand what
> p:wrap does, and I think I understand what group-adjacent is trying
> to do. But I can’t get it to work.
>
> I think I could get it working if someone would be so kind as to
> translate the middle sentence in this paragraph from the WD into
> English:
>
> The group-adjacent option can be used to group adjacent matching
> nodes in a single wrapper element. The specified XPath expression is
> evaluated for each matching node with that node as the XPath context
> node. Whenever two or more adjacent matching nodes have the same
> “group adjacent” value, they are wrapped together in a single
> wrapper element.
It's just like group-adjacent in xsl:for-each-group in XSLT 2.0 (not
that that necessarily helps at all).
The main time I use it in XSLT 2.0 is when I have some document
content, such as paragraphs and list items, and I want to group them
together so that all the list items get grouped into a list. For
example:
<p>
<p>
<li>
<li>
<p>
would become:
<p>
<p>
<ul>
<li>
<li>
</ul>
<p>
To do this, I use group-adjacent=". instance of element(li)". This is
an XPath (2.0) expression which returns true for <li> elements and
false for everything else. (An XPath 1.0 equivalent would be group-
adjacent="boolean(self::li)".) So the result of the evaluation is:
<p> false
<p> false
<li> true
<li> true
<p> false
Then the processor goes through and groups that first bunch of 'false'
elements together, then the 'true' elements together and then the
'false' elements together. So (with p:wrap) you get:
<wrapper>
<p>
<p>
</wrapper>
<wrapper>
<li>
<li>
</wrapper>
<wrapper>
<p>
</wrapper>
which you could then go ahead and process in other ways to unwrap the
<p>s and change the name of the wrapper of the <li>s.
That help any?
Jeni
--
Jeni Tennison
http://www.jenitennison.com
Received on Thursday, 18 September 2008 21:01:04 UTC