[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Select elements between others

Subject: Re: Select elements between others
From: "George Cristian Bina" <george@xxxxxxx>
Date: Tue, 20 Jan 2004 12:21:07 +0200
following sibling item
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@xxxxxxxxxxxxx
<oXygen/> XML Editor - http://www.oxygenxml.com/


----- Original Message -----
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, January 20, 2004 11:28 AM
Subject:  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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.