xsl-list
[Top] [All Lists]

Re: [xsl] XSLT repetition constructs comparison

2021-01-14 05:04:19
On Thu, Jan 14, 2021 at 2:49 PM Michael Kay mike(_at_)saxonica(_dot_)com <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

<xsl:iterate select="sort(student, (), function($s){$s/(fName, lName))">...


Thanks for this suggestion. I'll surely try this (at least to learn).

or if that's not possible (e.g because you need a descending sort), then
sort first (into a variable) using xsl:perform-sort.


This suggestion suits my use case. I wish to have flexibility within my
XSLT solution, where later moving to descending sort may be desirable.
Below is my try (which works) for this suggestion,

<?xml version="1.0"?>
<xsl:stylesheet version="3.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform";
                                               xmlns:xs="
http://www.w3.org/2001/XMLSchema";
                                               exclude-result-prefixes="xs">

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

   <xsl:template match="students">
      <html>
        <head>
           <title>Student list</title>
        </head>
        <body>
           <table>
              <tr>
                 <td><b>Roll No.</b></td>
                 <td><b>First name</b></td>
                 <td><b>Last name</b></td>
              </tr>
              <xsl:variable name="result_1" as="element(student)*">
                 <xsl:perform-sort select="student">
                    <xsl:sort select="fName"/>
                    <xsl:sort select="lName"/>
                 </xsl:perform-sort>
              </xsl:variable>
              <xsl:iterate select="$result_1">
                 <xsl:param name="total" select="0" as="xs:integer"/>
                 <xsl:on-completion>
                    <tr>
                      <td colspan="3">&#xa0;</td>
                    </tr>
                    <tr>
                      <td colspan="2"><b>Total no of students</b> : </td>
                      <td><xsl:value-of select="$total"/></td>
                    </tr>
                 </xsl:on-completion>
                 <tr>
                   <td align="center"><xsl:value-of select="rollNo"/>.</td>
                   <td><xsl:value-of select="fName"/></td>
                   <td><xsl:value-of select="lName"/></td>
                 </tr>
                 <xsl:next-iteration>
                   <xsl:with-param name="total" select="$total + 1"/>
                 </xsl:next-iteration>
              </xsl:iterate>
           </table>
        </body>
      </html>
   </xsl:template>

</xsl:stylesheet>

I personally, consider above XSLT stylesheet to be better than my solution
(3) in my earlier mail within this thread, since it reduces some of the
implementation noise as compared to my solution (3) written earlier.

Needless to say, I'm using Saxon as my XSLT processor.



-- 
Regards,
Mukul Gandhi
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>