RE: FW: [xsl] Siblings

Subject: RE: FW: [xsl] Siblings
From: "Karl Stubsjoen" <karl@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 15 Dec 2004 11:43:05 -0700
This is working, but had to resort to an XSL:CHOOSE, the modulo value (which
would result in 0) kept throwing me off.  Any ideas how to avoid the
XSL:CHOOSE and stick with pure mathematics?

<!-- next event can not result in value 0 -->
<xsl:variable name="next_event">
  <xsl:choose>
  <xsl:when test="((position() + $event_offset) mod ($event_count + 1)) =
0">
    <xsl:value-of select="((position() + $event_offset) mod ($event_count +
1)) + 1" />
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="(position() + $event_offset) mod ($event_count +
1)" />
  </xsl:otherwise>
  </xsl:choose>
</xsl:variable>

<!-- here is the sample xml -->
  <EVENT_TYPE type="ARTM">
    <EVENT olympic_order="1" display="Floor">1</EVENT>
    <EVENT olympic_order="2" display="Pommel">2</EVENT>
    <EVENT olympic_order="3" display="Rings">3</EVENT>
    <EVENT olympic_order="4" display="Vault">4</EVENT>
    <EVENT olympic_order="5" display="PBars">5</EVENT>
    <EVENT olympic_order="6" display="HiBar">6</EVENT>
    <EVENT olympic_order="7" display="AA">AA</EVENT>
  </EVENT_TYPE>

-----Original Message-----
From: Arun Sinha [mailto:arunsinha666@xxxxxxxxxxx]
Sent: Tuesday, December 14, 2004 12:54 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: FW: [xsl] Siblings



Hi Karl,

>You'll only have 4 results then.. I need all results.  Where the offset +
>current position is greater than total number of items, then the offset
>should result in the first item, 2nd item, and so on (it needs to wrap).
>

Use the following :-
<xsl:value-of select="elements/element[@item = ($offset mod
count(/elements/element)+1) ]" />

Cheers.
Arun

>From: "Karl Stubsjoen" <karl@xxxxxxxxxxxxxxxxxxxx>
>Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
>Subject: RE: FW: [xsl] Siblings
>Date: Tue, 14 Dec 2004 12:28:35 -0700
>
>Arun wrote:
>   I am not sure whether I have understood it clearly,
>   but what   about
>   using the following :-
>
>   <xsl:value-of select="/elements/element[@item =
>   ($offset + 1)]" />
>
>
>Karl
>
>-----Original Message-----
>From: Arun Sinha [mailto:arunsinha666@xxxxxxxxxxx]
>Sent: Tuesday, December 14, 2004 12:14 AM
>To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
>Subject: RE: FW: [xsl] Siblings
>
>
>
>Hi,
>
>
> >From: "Karl Stubsjoen" <karl@xxxxxxxxxxxxxxxxxxxx>
> >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> >Subject: FW: [xsl] Siblings
> >Date: Tue, 14 Dec 2004 11:53:58 -0700
> >
> >Woops, correction to 2nd "IF the offset were" result below:  should
>result
> >in "GRAPE", corrected with [GRAPE] below.
> >
> >-----Original Message-----
> >From: Karl Stubsjoen [mailto:karl@xxxxxxxxxxxxxxxxxxxx]
> >Sent: Tuesday, December 14, 2004 11:49 AM
> >To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >Subject: [xsl] Siblings
> >
> >
> >I need to offset a sibling match for an offset of X.  Example:
> >
> ><elements>
> ><element item="1">APPLE</element>
> ><element item="2">ORANGE</element>
> ><element item="3">GRAPE</element>
> ><element item="4">WATERMELON</element>
> ><element item="5">CRANBERRY</element>
> ></elements>
> >
> >If the offset were 0, then the result would be "APPLE", if the offse were
> >2,
> >then the result would be "ORANGE" -correction- [GRAPE].
>
>Well, corrected here.
>
> >
> >The template is always applied in order of the item, but the look up is
> >based on this offset value.
> >
> >So, the big challenge:  if the current item was 5 and the offset was 2,
> >then
> >the result would be "ORANGE".
>
>What about the above. Shouldn't it be "GRAPE" as well?
>
>I am not sure whether I have understood it clearly, but what about
>using the following :-
>
><xsl:value-of select="/elements/element[@item = ($offset+1)]" />
>
>Cheers.
>
>Arun
>
>_________________________________________________________________
>Chat with 1000s of singles.
>http://www.bharatmatrimony.com/cgi-bin/bmclicks1.cgi?74 Let
>BharatMatrimony.com's Instant Messenger show you how.
>

_________________________________________________________________
Cool ringtones, snazzy logos! Funny cards, addictive games!
http://www.msn.co.in/Mobile/ Get them all at one place!

Current Thread