Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Tree fragment between two tags?

Reply
Thread Tools

Tree fragment between two tags?

 
 
Jongware
Guest
Posts: n/a
 
      06-07-2010
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]
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-07-2010
Jongware wrote:
> 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.


--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
 
 
 
Jongware
Guest
Posts: n/a
 
      06-07-2010
On 07-Jun-10 17:00 PM, Martin Honnen wrote:
> Jongware wrote:
>> 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.


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

[Jw]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding an XML fragment as a child node in a pre-existing Element tree Rajarshi Python 1 02-11-2007 07:18 PM
test for an empty result tree fragment Andy Fish XML 1 02-08-2007 02:49 PM
add html fragment (and controls) to control tree Terry V ASP .Net Web Controls 0 08-25-2004 09:41 PM
B tree, B+ tree and B* tree Stub C Programming 3 11-12-2003 01:51 PM
Spanning Tree And Per Vlan Spanning Tree Amy L. Cisco 0 07-24-2003 10:01 PM



Advertisments