xsl-list
[Top] [All Lists]

Re: Select elements between others

2004-01-20 03:21:07
Something like below will do it.
You can count the items following the current selected block and substract
the items following the next block to determine how many items the current
block should contain. Then just copy the corresponding number of items
inside the current block.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
    <xsl:template match="/">
        <data>
            <xsl:apply-templates/>
        </data>
    </xsl:template>
    <xsl:template match="block">
        <block>
            <xsl:variable name="items"
select="count(following-sibling::item) -
count(following-sibling::block/following-sibling::item)"/>
            <xsl:copy-of select="following-sibling::item[position() &lt;=
$items]"/>
        </block>
    </xsl:template>
</xsl:stylesheet>


Best Regards,
 George
-------------------------------------------------------------
George Cristian Bina mailto:george(_at_)oxygenxml(_dot_)com
<oXygen/> XML Editor - http://www.oxygenxml.com/


----- Original Message -----
From: "Joe Fawcett" <joefawcett(_at_)hotmail(_dot_)com>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Tuesday, January 20, 2004 11:28 AM
Subject: [xsl] Select elements between others


I have received, what I consider to be, a badly designed xml file:
<data>
  <block/>
    <item>One</item>
    <item>Two</item>
  <block/>
    <item>One</item>
    <item>Two</item>
    <item>Three</item>
   <block/>
    <item>One</item>
</data>

I want to turn this into a more normal form to make it easier to manage:

<data>
  <block>
    <item>One</item>
    <item>Two</item>
  </block>
  <block>
    <item>One</item>
    <item>Two</item>
    <item>Three</item>
  </block>
  <block>
    <item>One</item>
  </block>
</data>

Thanks

Joe

_________________________________________________________________
Sign-up for a FREE BT Broadband connection today!
http://www.msn.co.uk/specials/btbroadband


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>