Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] sorting titles w stopwords but w/o value in every title node

From: "cking" <cking@---------->
To:
Date: 9/2/2004 11:34:00 AM
Hi Susan,

I modified the stylesheet to display the titles on first occurence in the table,
This is the output I get now:

    doc-number   title   description   arrival-date
    53690  American Artist  v.68:no.738(2004:Jan.)  02/26/2004
    57769  The American city & country  v.119:no.3(2004:Mar.)  03/25/2004
    57769       v.119:no.1(2004:Jan.)  02/11/2004
    58345  American demographics  v.26:no.3(2004:Apr.)  04/12/2004
    58345       v.26:no.2(2004:Mar.)  03/06/2004
    58345       v.26:no.1(2004:Feb.)  02/05/2004
    58615  Forbes.  v.173:no.5(2004:Mar.15)  03/15/2004
    58615       v.173:no.2(2004:Feb. 02)  01/21/2004
    58615       v.173:no.1(2004:Jan. 12)  01/12/2004

I added a key:

    <xsl:key name="titles" match="//section-02/title[string(.)]" use="../doc-number"/>

And then instead of directly writing to the table, I created another global variable, 
already sorted, structured like

<output>
    <title doc-number="53690" title="American Artist" 
        description="v.68:no.738(2004:Jan.)" arrival-date="02/26/2004"/>
    <title doc-number="57769" title="The American city &amp; country" 
        description="v.119:no.3(2004:Mar.)" arrival-date="03/25/2004"/>
    <title doc-number="57769" title="The American city &amp; country" 
        description="v.119:no.1(2004:Jan.)" arrival-date="02/11/2004"/>
    <title doc-number="58345" title="American demographics" 
        description="v.26:no.3(2004:Apr.)" arrival-date="04/12/2004"/>
    ...
</output>

where every record has its full title.

Then, when writing the output in the table, I only print the title if it's the first
occurence of that doc-number.

<xsl:stylesheet version="1.0"
   xmlns="http://www.w3.org/1999/xhtml"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:exsl="http://exslt.org/common"
   xmlns:sw="http://my.stopwords/sw"
  extension-element-prefixes="exsl sw"
   >

 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  />

 <sw:stop>
  <sw:word>the</sw:word>
  <sw:word>a</sw:word>
  <sw:word>an</sw:word>
 </sw:stop>

 <xsl:variable name="stop-words" select="document('')/xsl:stylesheet/sw:stop/sw:word"/>
 <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
 <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>

 <xsl:key name="titles" match="//section-02/title[string(.)]" use="../doc-number"/>

 <xsl:variable name="sort-titles">
  <xsl:for-each select="//section-02">
   <xsl:if test="string(title)">
    <title doc-number="{doc-number}">
     <xsl:variable name="lower-title" select="translate(title, $uppercase, $lowercase)"/>
     <xsl:choose>
      <xsl:when test="$stop-words[starts-with($lower-title, concat(translate(., $uppercase, $lowercase), ' '))]">
       <xsl:value-of select="substring-after($lower-title,' ')"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="$lower-title"/>
      </xsl:otherwise>
     </xsl:choose>
    </title>
   </xsl:if>
  </xsl:for-each>
 </xsl:variable>

 <xsl:variable name="output">
  <xsl:for-each select="//section-02/title">
   <xsl:sort select="exsl:node-set($sort-titles)/*[@doc-number = current()/../doc-number]"/>
   <xsl:sort select="number(concat(substring(../arrival-date, 7,4),
    substring(../arrival-date, 1,2), substring(../arrival-date, 4,2)))"
    order="descending"/>
   <title doc-number="{../doc-number}" title="{key('titles', ../doc-number)}" 
    description="{../description}" arrival-date="{../arrival-date}"/>
  </xsl:for-each>
 </xsl:variable>

 <xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml"><head><title>sort without stop-words</title></head><body>
   <table border="1">
    <tr>
     <th>doc-number</th>
     <th>title</th>
     <th>description</th>
     <th>arrival-date</th>
    </tr> 
    <xsl:for-each select="exsl:node-set($output)/*">
     <xsl:variable name="title">
      <xsl:if test="not(preceding-sibling::*[@doc-number = current()/@doc-number])">
       <xsl:value-of select="@title"/>
      </xsl:if>
     </xsl:variable>
     <tr>
      <td><xsl:value-of select="@doc-number"/></td>
      <td><xsl:value-of select="$title"/></td>
      <td><xsl:value-of select="@description"/></td>
      <td><xsl:value-of select="@arrival-date"/></td>
     </tr>
    </xsl:for-each>
   </table>
  </body></html>
 </xsl:template>

</xsl:stylesheet>

Cheers,
Anton Triest


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent