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

Re: Looping on a maximum value

Subject: Re: Looping on a maximum value
From: Steve Tinney <stinney@xxxxxxxxxxxxx>
Date: Wed, 22 Dec 1999 14:16:54 -0500
xsl maximum value
Here is one way to do it:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

<xsl:variable name="maxcol">
  <xsl:for-each select="/items/item">
    <xsl:sort select="@col" order="descending" data-type="number"/>
    <xsl:if test="position()=1">
      <xsl:value-of select="@col"/>
    </xsl:if>
  </xsl:for-each>
</xsl:variable>

<xsl:template match="/">
  <row>
    <xsl:call-template name="printitems"/>
  </row>
</xsl:template>

<xsl:template name="printitems">
  <xsl:param name="index" select="1"/>
  <xsl:for-each select="/items/item[@col=$index]">
    <column number="{@col}" instance="{position()}">
      <xsl:copy-of select="*"/>
    </column>
  </xsl:for-each>
  <xsl:if test="$index &lt; $maxcol">
    <xsl:call-template name="printitems">
      <xsl:with-param name="index" select="$index + 1"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

 Steve

Brett McLaughlin wrote:
> 
> Suppose I have an XML fragment that looks something like:
> 
> <!-- Content -->
> 
>   <items>
>    <item col="2">
>     <name>Some Name</name>
>     <content>Some Content</content>
>    </item>
>    <item col="4">
>     <name>Some Other Name</name>
>     <content>Some More Content</content>
>    </item>
>    <item col="3">
>     <name>Some New Name</name>
>     <content>Some Crazy Content</content>
>    </item>
>    <item col="2">
>     <name>Some Guy's Name</name>
>     <content>Some Content that is Different</content>
>    </item>
>   </items>
> 
> <!-- More Content -->
> 
> I want to do the equivalent of:
> 
> <!-- Get the highest column number and put it in an xsl variable called
> numCols -->
> 
> <!-- Loop from 0 to that variable (numCols) - 1 [or 1 .. numCols] -->
> 
>   <xsl:apply-templates select="item[@col=counter]" />
> 
> Does that make sense?  Basically I need to get the number of columns I
> will need, iterate from 1 to that number, and at each pass use the
> counter to get all the items that specify that column as their col
> attribute.
> 
> Thanks
> Brett
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
----------------------------------------------------------------------
Steve Tinney                                        Babylonian Section
                                 *   University of Pennsylvania Museum
stinney@xxxxxxxxxxxxx                          Phila, PA. 215-898-4047


 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.