This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Ordered Records


It's reaaly not that hard with XSLT :-)

ok an example:

so lots of records throughout the XML, you want only to show the smallest 10.

Based on your XML I created a little example.
First sort your records from small to big, then only do something with the 
first 10.

Cheers
RH

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

    <xsl:template match="/">
       <xsl:apply-templates select="//record">
          <xsl:sort select="number" data-type="number" />
       </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="record">

       <xsl:choose>
          <xsl:when test="position() &lt; 11">
             <record>
                <xsl:comment>position = <xsl:value-of select="position()" 
/></xsl:comment>
                <xsl:apply-templates select="number" />
             </record>
          </xsl:when>
          <xsl:otherwise>
             <xsl:comment>at least 10 records have smaller 
numbers</xsl:comment>
          </xsl:otherwise>
       </xsl:choose>

    </xsl:template>

    <xsl:template match="number">
       <number>
          <xsl:apply-templates />
       </number>
    </xsl:template>

</xsl:stylesheet>

XML
<document>
    <record-set>
       <record>
          <number>100</number>
       </record>

       <record>
          <number>5</number>
       </record>

       <record>
          <number>102</number>
       </record>

       <record>
          <number>51</number>
       </record>

       <record>
          <number>101</number>
       </record>

       <record>
          <number>52</number>
       </record>

       <record>
          <number>12</number>
       </record>

       <record>
          <number>15</number>
       </record>
    </record-set>

    <record-set>
       <record>
          <number>19</number>
       </record>

       <record>
          <number>29</number>
       </record>

       <record>
          <number>10</number>
       </record>

       <record>
          <number>19</number>
       </record>

       <record>
          <number>291</number>
       </record>

       <record>
          <number>30</number>
       </record>

       <record>
          <number>99</number>
       </record>

       <record>
          <number>59</number>
       </record>

       <record>
          <number>10</number>
       </record>
    </record-set>
</document>

HTML:
<record>
<!--position = 1-->
    <number>5</number>
</record>

<record>
<!--position = 2-->
    <number>10</number>
</record>

<record>
<!--position = 3-->
    <number>10</number>
</record>

<record>
<!--position = 4-->
    <number>12</number>
</record>

<record>
<!--position = 5-->
    <number>15</number>
</record>

<record>
<!--position = 6-->
    <number>19</number>
</record>

<record>
<!--position = 7-->
    <number>19</number>
</record>

<record>
<!--position = 8-->
    <number>29</number>
</record>

<record>
<!--position = 9-->
    <number>30</number>
</record>

<record>
<!--position = 10-->
    <number>51</number>
</record>

<!--at least 10 records have smaller numbers-->
<!--at least 10 records have smaller numbers-->
<!--at least 10 records have smaller numbers-->
<!--at least 10 records have smaller numbers-->
<!--at least 10 records have smaller numbers-->
<!--at least 10 records have smaller numbers-->
<!--at least 10 records have smaller numbers-->



At 12:37 PM 2/4/02 +0100, you wrote:
>Hi,
>
>I have the following XML document:
>
><record-set>
><record>
>     <number>N1</number>
></record>
>:
>:
>:
>:
><record>
>     <number>Nn</number>
></record>
></record-set>
>:
>:
>:
><record-set>
><record>
>     <number>M1</number>
></record>
>:
>:
>:
>:
><record>
>     <number>Mn</number>
></record>
></record-set>
>
>In each record-set the records are ordinated (the first has the smallest
>number, the last has the bigger number).
>I'd like to take, between all record-set, only the 10 records with smallest
>number and print them on the screen.
>
>Can I do this with XSL? How?
>
>Somebody, if possible, can give me an hint for this problem?
>
>Thanks in advance.
>
>Stefano
>
>
>
>
>---
>Outgoing mail is certified Virus Free. (CopyRight FLASHH!)
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.320 / Virus Database: 179 - Release Date: 30/01/02
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]