[xsl] Assistance with the Muenchian method

Subject: [xsl] Assistance with the Muenchian method
From: "Renick, Garrel" <garrel@xxxxxxxx>
Date: Mon, 10 Dec 2001 13:11:02 -0600
Hello. I desperately need assistance with removing duplicate XML data.
I'm attempting to use the Muenchian method referred to in some of the
posts on this list, but I'm not having success. 

I'm using the Xalan XSL processor that comes with the Tomcat application
server.

My data looks like this:

<document>
<output scope="session">
  <userData>
    <publish pid="6">
      <website oid="1" wid="5" path="/:/" virtual="true" secure="false"
tomcat="false">
        <name>Global</name>
        <location type="http">
          <path>WebPublish/web/www</path>
          <url>http://null/</url>
        </location>
        <location type="log">
          <path>WebPublish/web/logs</path>
        </location>
      </website>
      <website webdomain="www.test.org" oid="1" wid="1"
path="/:/www.test.org" virtual="false" secure="false" tomcat="true">
        <name>test Documentation</name>
        <location type="http">
          <path>WebPublish/web/www.test.org/www</path>
          <url>http://www.test.org/</url>
        </location>
      </website>
    </publish>
    <publish pid="29">
      <website oid="1" wid="5" path="/:/" virtual="true" secure="false"
tomcat="false">
        <name>Global</name>
        <location type="http">
          <path>WebPublish/web/www</path>
          <url>http://null/</url>
        </location>
        <location type="log">
          <path>WebPublish/web/logs</path>
        </location>
      </website>
    </publish>
  </userData>
</output>
</document>

What I need to do is build an html select list with information from
every <website>, but only display each website once...the <website> with
the same @wid may appear multiple times in the data with a different
<publish> parent.

I'm currently doing the following in my code:

<xsl:key name="groups-by-wid"
match="/document/output[@scope='session']/userData/publish/website"
use="@wid"/>
<xsl:apply-templates
select="/document/output[@scope='session']/userData">

<xsl:template match="userData">
  <xsl:for-each
select="publish/website[generate-id()=generate-id(key('groups-by-wid',
@wid)[1])]">
    <xsl:sort select="@path"/> 
    <xsl:variable name="wid" select="@wid"/>
    <xsl:for-each select="key('groups-by-wid', $wid)">
      <xsl:variable name="path" select="@path"/>
      <xsl:variable name="wid" select="@wid"/>
      <option value="{$wid}"><xsl:value-of select="$path"/></option>
    </xsl:for-each>
  </xsl:for-each>
</xsl:template>

This isn't working. Two options for the website with wid=5 are
displayed. I think it must have something to do with the <website
wid="5"> elements having different parents, but I'm not sure.

Do any of you with experience in this technique see the problem with my
code? 

Regards,
Garrel Renick
garrel@xxxxxxxx 

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


Current Thread