[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Merging attribute values to unique list


Subject: RE: [xsl] Merging attribute values to unique list
From: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Fri, 1 Aug 2003 08:09:41 -0400

Hey James,

Here's a solution that can be refactored to be a bit more generalized:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:template match="/">
<p>See the reading for:
  <xsl:variable name="unique-wit-list">
    <xsl:call-template name="unique-token-list">
      <xsl:with-param name="str">
        <xsl:for-each select="//body">
          <xsl:text> </xsl:text><xsl:value-of select="@wit"/>
        </xsl:for-each>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:variable>
  <xsl:for-each select="msxsl:node-set($unique-wit-list)/*">
    <xsl:sort select="name()" data-type="text"/>
    <a href="foo/a1.xml?wit='{name()}'"><xsl:value-of select="name()"/></a>
  </xsl:for-each>
</p>
</xsl:template>
<xsl:template name="unique-token-list">
  <xsl:param name="str"/>
  <xsl:param name="nl"/>
  <xsl:variable name="token"
select="substring-before(concat(normalize-space($str),' '),' ')"/>
  <xsl:choose>
    <xsl:when test="string-length($token) > 0">
      <xsl:call-template name="unique-token-list">
        <xsl:with-param name="str" select="substring-after($str,$token)"/>
        <xsl:with-param name="nl">
          <xsl:copy-of select="msxsl:node-set($nl)/*"/>
          <xsl:if test="count(msxsl:node-set($nl)/*[name()=$token]) = 0">
            <xsl:element name="{$token}"/>
          </xsl:if>
        </xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select="msxsl:node-set($nl)"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
</xsl:stylesheet>


I believe the FXSL library has templates that tokenize and remove duplicates
(distinct) ... so, I suspect a less custom solution could be crafted from
that library.  I also think the EXSL(?) library has the same capabilities.

Cheers,
Jeff



-----Original Message-----
From: James Cummings [mailto:James.Cummings@xxxxxxxxx]
Sent: Friday, August 01, 2003 7:17 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Merging attribute values to unique list



Hi there,

This is similar to something I asked months ago, and you'd
think I'd be able to figure it out but... assuming you have
a file like>


<foo id="a1">
<body wit="A B E D">some stuff</body>
<body wit="C A G">some other stuff</body>
</foo>

What I want to produce is a list of links one for each unique witness,
so in this case something like:

<p>See the reading for:
<a href="foo/a1.xml?wit="A">A</a>
<a href="foo/a1.xml?wit="B">B</a>
<a href="foo/a1.xml?wit="C">C</a>
<a href="foo/a1.xml?wit="D">D</a>
<a href="foo/a1.xml?wit="E">E</a>
<a href="foo/a1.xml?wit="G">G</a>
</p>

So, I'm assuming what needs to happen is that I need to somehow produce
a list of each of the tokenized contents of //body/@wit which are
then sorted and made unique. Any suggestions on how to go about this
using Xalan inside cocoon-2.1?  I.e. I have some ideas on how to do it
with saxon extensions/xslt 2.0, but not inside cocoon.  Any suggestions
appreciated!

-James

-- 
Dr James Cummings, James.Cummings@xxxxxxxxx, http://www.uea.ac.uk/~q503
Cursus Project, School of Music, University of East Anglia,
Norwich, Norfolk, NR4 7TJ, UK  Tel:(01603)593-595




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

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



Current Thread