Tree fragment between two tags?

Discussion in 'XML' started by Jongware, Jun 7, 2010.

  1. Jongware

    Jongware Guest

    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]
    Jongware, Jun 7, 2010
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Jun 7, 2010
    #2
    1. Advertising

  3. Jongware

    Jongware Guest

    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]
    Jongware, Jun 7, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,110
  2. Andy Fish
    Replies:
    1
    Views:
    442
    Richard Tobin
    Feb 8, 2007
  3. Rajarshi
    Replies:
    1
    Views:
    536
    Gabriel Genellina
    Feb 11, 2007
  4. Terry V

    add html fragment (and controls) to control tree

    Terry V, Aug 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    1,036
    Terry V
    Aug 25, 2004
  5. replacing tags between tags

    , Sep 18, 2005, in forum: Perl Misc
    Replies:
    9
    Views:
    127
    J├╝rgen Exner
    Sep 19, 2005
Loading...

Share This Page