xsl-list
[Top] [All Lists]

Re: [xsl] Sorting and navigation

2007-09-06 04:53:25
Coppens Benoît (All4IT) wrote:

  Benoit,

Table must be sorted first by Author and then by ID
Next and Previous columns contain the ID of the next/previous
document

  If you can use node-set(), see the David's answer.  If you really,
really can't, you can use the solution at the end of the email (but
this is really tricky, it will perform sorting for each next and each
previous!).

  BTW I saw a lot of people saying they are using Xalan only because
this is the default processor in the JRE.  If this is the case, I would
suggest to have a look at Saxon.  This should be easy to plug in your
application instead of Xalan, and give you the power of XSLT 2.0.

   <xsl:template match="ALL_DOCUMENTS">
      <xsl:text>ID | AUTHOR | NEXT | PREVIOUS&#10;</xsl:text>
      <xsl:text>-----------------------------&#10;</xsl:text>
      <xsl:variable name="docs" select="DOCUMENT"/>
      <xsl:for-each select="$docs">
         <xsl:sort select="AUTHOR"/>
         <xsl:sort select="ID"/>
         <xsl:variable name="pos" select="position()"/>
         <!-- id -->
         <xsl:value-of select="format-number(ID, '00')"/>
         <xsl:text> | </xsl:text>
         <!-- author -->
         <xsl:value-of select="AUTHOR"/>
         <xsl:text>     | </xsl:text>
         <!-- next -->
         <xsl:choose>
            <xsl:when test="$pos = last()">
               <xsl:text> *</xsl:text>
            </xsl:when>
            <xsl:otherwise>
               <xsl:for-each select="$docs">
                  <xsl:sort select="AUTHOR"/>
                  <xsl:sort select="ID"/>
                  <xsl:if test="position() = ($pos + 1)">
                     <xsl:value-of select="format-number(ID, '00')"/>
                  </xsl:if>
               </xsl:for-each>
            </xsl:otherwise>
         </xsl:choose>
         <xsl:text>   | </xsl:text>
         <!-- previous -->
         <xsl:choose>
            <xsl:when test="$pos = 1">
               <xsl:text> *</xsl:text>
            </xsl:when>
            <xsl:otherwise>
               <xsl:for-each select="$docs">
                  <xsl:sort select="AUTHOR"/>
                  <xsl:sort select="ID"/>
                  <xsl:if test="position() = ($pos - 1)">
                     <xsl:value-of select="format-number(ID, '00')"/>
                  </xsl:if>
               </xsl:for-each>
            </xsl:otherwise>
         </xsl:choose>
         <xsl:text>&#10;</xsl:text>
      </xsl:for-each>
   </xsl:template>

  Regards,

--drkm

























      
_____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>