Tree fragment between two tags?

J

Jongware

Hi all,

Given an xml file with a linear set

<a>1</a>
<b>2</b>
<b>3</b>
<b>4</b>
<a>5</a>
<b>6</b>
<b>7</b>

how do I get separate groups to work on of the first set of tags from
<a>(1) to <b>(4) and the second set from <a>(5) to <b>7?

The number of items may vary from group to group, as does the total
number of groups (determined by the number of <a> tags). Purpose is to
be able to sort the sub-items *per group* -- in essence, you can
consider the <a> elements the same as the <b> ones, they act as
separators for each sub-group.

XSLT2.0 is no problem, I'm using Saxon 8.0 (and so far blissfully
unaware of any limitations it may have with 2.0).

TIA!
[Jw]
 
M

Martin Honnen

Jongware said:
Hi all,

Given an xml file with a linear set

<a>1</a>
<b>2</b>
<b>3</b>
<b>4</b>
<a>5</a>
<b>6</b>
<b>7</b>

how do I get separate groups to work on of the first set of tags from
<a>(1) to <b>(4) and the second set from <a>(5) to <b>7?
XSLT2.0 is no problem, I'm using Saxon 8.0 (and so far blissfully
unaware of any limitations it may have with 2.0).

Saxon 8.9 is the first Saxon version to implement the W3C standard XSLT
2.0 and XPath 2.0 so if you want to use XSLT 2.0 then I recommend to
upgrade to the current release 9.2 of Saxon.

As for the problem, XSLT 2.0 has
<xsl:for-each-group select="*" group-starting-with="a">
<group>
<xsl:copy-of select="current-group()"/>
</group>
</xsl:for-each-group>
You could use that code inside a template matching the common parent
element of the nodes you have shown.
 
J

Jongware

Saxon 8.9 is the first Saxon version to implement the W3C standard XSLT
2.0 and XPath 2.0 so if you want to use XSLT 2.0 then I recommend to
upgrade to the current release 9.2 of Saxon.

As for the problem, XSLT 2.0 has
<xsl:for-each-group select="*" group-starting-with="a">
<group>
<xsl:copy-of select="current-group()"/>
</group>
</xsl:for-each-group>
You could use that code inside a template matching the common parent
element of the nodes you have shown.

Marvellous! First time I ever used for-each-group -- it works straight
away. Thanks!

[Jw]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top