[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Merging attribute values to unique list

Subject: Re: Merging attribute values to unique list
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 2 Aug 2003 09:52:09 +0200
xsl unique list
Here's the solution using the tokenizer from FXSL (the "str-split-to-words"
template). Note that you can specify more than one possible delimiter, e.g.
";, '&x9;&xA;&xD;'"

The following transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ext="http://exslt.org/common"
 exclude-result-prefixes="ext"
 >

 <xsl:import href="strSplit-to-Words.xsl"/>

 <xsl:key name="kDist" match="word" use="."/>

 <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">
    <xsl:variable name="vAllWits">
      <xsl:for-each select="/*/body">
        <xsl:value-of select="concat(' ', @wit)"/>
      </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="vTokens">
      <xsl:call-template name="str-split-to-words">
        <xsl:with-param name="pStr" select="$vAllWits"/>
        <xsl:with-param name="pDelimiters" select="' '"/>
      </xsl:call-template>
    </xsl:variable>

    <p>See the reading for:<xsl:text>&#xA;</xsl:text>
      <xsl:for-each
           select="ext:node-set($vTokens)/word
                                [generate-id()
                                =
                                 generate-id(key('kDist', .)[1])
                                 ]">
        <xsl:sort/>

        <a href="foo/a1.xml?wit='{.}'">
          <xsl:value-of select="."/>
        </a>
      </xsl:for-each>
    </p>
  </xsl:template>
</xsl:stylesheet>


when applied against this source.xml:

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

produces the wanted result:

<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>


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

"James Cummings" <James.Cummings@xxxxxxxxx> wrote in message
news:Pine.OSF.4.44.0308011213270.10128-100000@xxxxxxxxxxxxxxxxxx
>
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.