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

Re: if a condition is not met

Subject: Re: if a condition is not met
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Tue, 15 May 2007 18:15:27 +0200
Re:  if a condition is not met
Hi David,

Perhaps something like this (XSLT 2.0), taken all your requirements, if I understood them correctly, but it's a rather naive attempt, I'm sure it can be far simpler than this (I loathe the repeated logic...):


<xsl:template match="/" name="main">
<xsl:for-each-group
select="times/time[position() != last()]"
group-starting-with="node()[@time = ../../cells/cell/(@startTime, @endTime)]">


<!-- all starting times -->
<xsl:apply-templates select="current-group()[1][@time = ../../cells/cell/@startTime]" mode="start-time" />
<!-- all times 'during' an event -->
<xsl:apply-templates select="current-group()[1][@time = ../../cells/cell/@startTime]/current-group()[position() > 1]" />
<!-- all times that form a gap -->
<xsl:apply-templates select="current-group()[1][not(@time = ../../cells/cell/@startTime)]/current-group()" mode="gap-time" />
</xsl:for-each-group>
</xsl:template>


<xsl:template match="time" mode="start-time">
<start-time time="{.}" user="{../../cells/cell[@startTime = current()/@time]}" />
</xsl:template>


<xsl:template match="time">
   <occupied-time time="{.}" />
</xsl:template>

<xsl:template match="time" mode="gap-time">
   <gap time="{.}" />
</xsl:template>


This will output, taken your input, the following XML:


<start-time time="11:00" user="Marquette"/>
<occupied-time time="11:30"/>
<occupied-time time="12:00"/>
<occupied-time time="12:30"/>
<gap time="01:00"/>
<gap time="01:30"/>
<start-time time="02:00" user="Birnbaum"/>
<occupied-time time="02:30"/>
<start-time time="03:00" user="Konsko"/>
<occupied-time time="03:30"/>
<start-time time="04:00" user="Frasier"/>
<occupied-time time="04:30"/>


Since you say that you only need the 'gap' time, you can suffice with the for-each-group and the following as its content, with or without a mode, depending on what you want:


<xsl:apply-templates select="current-group()[1][not(@time = ../../cells/cell/@startTime)]/current-group()" />


Can someone, btw, elaborate on the following: Why is it that a statement like current-group()[some-predicate]/following-sibling::* will return *all* following sibling and not only the elements that are part of the current group? My guess is that current-group() retains its bond with the original tree, is that correct?


To workaround this, I know that you can treat the current-group() results as a document-node when you copy it into a variable and go from there.

Cheers,
-- Abel Braaksma




David J Birnbaum wrote:


for each time element
is there a cell that occurs during (but does not begin) that time?
if any cell meets that condition, do nothing at all within that pass through the time loop
if no cell meets that condition, do something, but do it only once (total) during that pass through the time loop

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-2011 All Rights Reserved.