Subject: Re: block selection question (XSLT 1.0)
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Fri, 6 May 2011 10:55:13 +0100
|
On 6 May 2011 10:13, Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> wrote:
> Hello,
>
> I know that this is basic but I cannot get it done correctly.
>
> Input:
> <lines>
> <line></line>
> <line>A1</line>
> <line>1</line>
> <line>B1</line>
> <line></line>
> <line>A2</line>
> <line>2</line>
> <line>2</line>
> <line>2</line>
> <line>B2</line>
> <line></line>
> <line></line>
> </lines>
>
> Intended output (blockwise, start at A, all including next B):
> <line>A1</line>
> <line>1</line>
>
> <line>A2</line>
> <line>2</line>
> <line>2</line>
> <line>2</line>
A group-starting-with solution:
<xsl:variable name="a-to-z" select="('a', 'b')"/>
<xsl:template match="/">
<lines>
<xsl:for-each-group select="$input/lines/line[normalize-space(.)]"
group-starting-with="line[lower-case(substring(., 1, 1)) = $a-to-z]">
<xsl:if test="current-group()[2]">
<group>
<xsl:copy-of select="current-group()"/>
</group>
</xsl:if>
</xsl:for-each-group>
</lines>
</xsl:template>
...should be enough to start with.
--
Andrew Welch
http://andrewjwelch.com
|