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

Re: A challenge.. Group Periods of Data (1..5, 2..8,

Subject: Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14)
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Fri, 6 May 2005 22:39:47 -0700 (PDT)
xsl copy of group data
Hi Karl,
  I approached the problem as follows -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" />

<xsl:variable name="start1" select="1" />
<xsl:variable name="end1" select="12" />
<xsl:variable name="start2" select="14" />
<xsl:variable name="end2" select="30" />
  
<xsl:template match="/A">
   <result>
     <period begins="{$start1}" ends="{$end1}">
       <xsl:for-each select="B[(@period_begin &gt;=
$start1) and (@period_end &lt;= $end1)]">
         <xsl:sort select="@period_begin"
data-type="number" />
         <xsl:copy-of select="." />
       </xsl:for-each>
     </period>
     <period begins="{$start2}" ends="{$end2}">
       <xsl:for-each select="B[(@period_begin &gt;=
$start2) and (@period_end &lt;= $end2)]">
         <xsl:sort select="@period_begin"
data-type="number" />
         <xsl:copy-of select="." />
       </xsl:for-each>
     </period>
   </result>
</xsl:template>
  
</xsl:stylesheet>

When the above XSLT stylesheet is given this XML as
input -

<?xml version="1.0" encoding="UTF-8"?>
<A>
  <B period_begin="14" period_end="16"/>
  <B period_begin="2" period_end="7"/>
  <B period_begin="16" period_end="20"/>
  <B period_begin="1" period_end="5"/>
  <B period_begin="4" period_end="12"/>
  <B period_begin="16" period_end="30"/>
  <B period_begin="3" period_end="10"/>
</A>

The output recieved is -

<?xml version="1.0" encoding="utf-8"?>
<result>
   <period begins="1" ends="12">
      <B period_begin="1" period_end="5"/>
      <B period_begin="2" period_end="7"/>
      <B period_begin="3" period_end="10"/>
      <B period_begin="4" period_end="12"/>
   </period>
   <period begins="14" ends="30">
      <B period_begin="14" period_end="16"/>
      <B period_begin="16" period_end="20"/>
      <B period_begin="16" period_end="30"/>
   </period>
</result>

The other answers are brilliant.. But I thought of
giving it a try myself, and seeing how my approach
will differ with other people's answers! 

(I don't know if I should have answered at this stage,
as your question is already answered :) But just
thought of..)

Regards,
Mukul

--- Karl Stubsjoen <kstubs@xxxxxxxxx> wrote:
> A challenge, group the following XML into 2 periods.
>  The periods are
> arbitrary, but for this example they happen to be:
> Period 1:  1 - 12
> Period 2:  14 - 30
> 
> Expected Result:
> <result>
>   <period begins="1" ends="12">
>     <B period_begin="1" period_end="5"/>
>     <B period_begin="2" period_end="7"/>
>     <B period_begin="3" period_end="10"/>
>     <B period_begin="4" period_end="12"/>
>   </period>
>   <period begins="14" ends="30">
>     <B period_begin="14" period_end="16"/>
>     <B period_begin="16" period_end="20"/>
>     <B period_begin="16" period_end="30"/>
>   </period>
> </result>
> 
> Source XML / Result (sorted)
> <A>
>   <B period_begin="1" period_end="5"/>
>   <B period_begin="2" period_end="7"/>
>   <B period_begin="3" period_end="10"/>
>   <B period_begin="4" period_end="12"/>
>   <B period_begin="14" period_end="16"/>
>   <B period_begin="16" period_end="20"/>
>   <B period_begin="16" period_end="30"/>
> </A>
> 
> Source XML / Result (un-sorted)
> <A>
>   <B period_begin="14" period_end="16"/>
>   <B period_begin="2" period_end="7"/>
>   <B period_begin="16" period_end="20"/>
>   <B period_begin="1" period_end="5"/>
>   <B period_begin="4" period_end="12"/>
>   <B period_begin="16" period_end="30"/>
>   <B period_begin="3" period_end="10"/>
> </A>
> 
> 


		
Discover Yahoo! 
Stay in touch with email, IM, photo sharing and more. Check it out! 
http://discover.yahoo.com/stayintouch.html

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.