Re: [xsl] mixed content grouping by whitespace

Subject: Re: [xsl] mixed content grouping by whitespace
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 12 Apr 2010 07:34:47 -0400
At 2010-04-12 10:52 +0100, James Cummings wrote:
On Mon, Apr 12, 2010 at 01:19, G. Ken Holman
<gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
> When I completed my solution I found it almost identical to yours, except
> that I used group-starting-with=. B I also
could not think of a way to do it
> in one pass.

It seems that when the solution requires a two pass one done all in
one stylesheet, I have difficulty getting my head around it. From what
I can see yours is basically similar to Gerrit's but uses an element
in a my: namespace.  You group starting with my:text (which surrounds
the whitespace)...

> B  B <xsl:for-each-group select="$content"
> B  B  B  B  B  B  B  B  B  B  B  B group-starting-with="my:text">
> B  B  B <xsl:copy-of select="self::my:text/node()"/>
> B  B  B <w>
> B  B  B  B <xsl:copy-of select="current-group()[not(self::my:text)]"/>
> B  B  B </w>
> B  B </xsl:for-each-group>

Where Gerrit took the value of current-group when the
current-grouping-key was a true boolean, you do a copy-of but then
select the nodes inside the self::my:text .... that confused me for a
bit and I'm not sure I don't see why you don't just do <xsl:value-of
select="self::my:text"/> (hrmm, that I say 'just' here is probably
unfair, they both work out as the same thing.)

They do, the end result is the same. But I perceived what I was doing as preserving the text as a text node and then copying the text node. Asking for the value of an element does a recursive descent below the element looking for all text nodes. Sure there is only one, so it isn't going to go far. But the philosophy of taking the value of an element to me was different than simply copying that text node I created to preserve the white-space. I wrote it to support the way I was thinking about it.

This works because
you're doing group-starting-with() so you know the first thing in the
group is the my:text node.

The first thing *may* be a my:text node. All of the lines don't start with white-space, so all of the lines will start with a group without a my:text element. Remember that in the start of a group the current node is the first member of the group. Which is why I'm using the self:: axis to ensure that I'm only copying the nodes of the first of the group if the first of the group is a my:text element.

People gripe about namespaces but note how I was
able to use my own namespace to add unambiguously
my own information to the old information.

These things are  starting to make my brain melt less than previously,
which is a start I guess.

Good! Grouping is a very powerful tool in XSLT 2.0.


. . . . . . . . . . . . Ken

--
XSLT/XQuery training:         San Carlos, California 2010-04-26/30
Principles of XSLT for XQuery Writers: San Francisco,CA 2010-05-03
XSLT/XQuery training:                 Ottawa, Canada 2010-05-10/14
XSLT/XQuery/UBL/Code List training: Trondheim,Norway 2010-06-02/11
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread