|
[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,
Hi Karl,
At 04:16 PM 5/3/2005, you wrote: A challenge, group the following XML into 2 periods. Okay, I'll bite. (Anyone else answering this challenge, read no further till you're done!) I'm assuming your target periods are known at time of writing. (If only known at run-time, they can be parameterized. If not even that, more specification is called for.) I'm also assuming your data is known to be valid to the assumptions made for sorting (for example, there's no B whose beginning is in one period and end is in another) -- there's no exception-handling for any of that. Here goes: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:local="data:hey-david" exclude-result-prefixes="local"> <xsl:output indent="yes"/> <xsl:variable name="period-groups" xmlns="data:hey-david"> <group start="1" end="12"/> <group start="14" end="30"/> </xsl:variable> <xsl:variable name="periods" select="//*[@period_begin]"/> <xsl:template match="/">
<result>
<xsl:apply-templates select="document('')/*/*/local:group"/>
</result>
</xsl:template><xsl:template match="local:group"> <xsl:variable name="start" select="@start"/> <xsl:variable name="end" select="@end"/> <period begins="{@start}" ends="{@end}"> <xsl:for-each select="$periods[@period_begin >= $start and @period_end <= $end]"> <xsl:sort select="@period_begin"/> <xsl:sort select="@period_end"/> <xsl:copy-of select="."/> </xsl:for-each> </period> </xsl:template> </xsl:stylesheet> Run on the input you provided, this gets you the output you say you want. Cheers, Wendell The periods are arbitrary, but for this example they happen to be: Period 1: 1 - 12 Period 2: 14 - 30 ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








