Re: [xsl] Split and Found unique values

Subject: Re: [xsl] Split and Found unique values
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 7 Dec 2006 14:42:01 GMT
your posted input doesn't match your code,  <target:row is in a target
namespace but
match='xml/target' use=
woul match an element target in no namespace.

I don't think you want to do this:
                  <xsl:for-each select='$Rowset[generate-id() = generate-id(key("Category", @Category))]'>
as that handles each complete category separately, you want to stick
them all togeter first and then split/sort. so

so something like

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:t="t" >

 <xsl:output indent="yes"/>

<xsl:key name='Category' match='t:row' use='@Category'/>
<xsl:variable name='seen' select="''"/>
 
  <xsl:template match="x">
              <select name="x" multiple="multiple">
                     <xsl:call-template name="Split">
                         <xsl:with-param name="strInput">
<xsl:for-each select="t:row/@Category">
  <xsl:value-of select="."/>
  <xsl:if test="position()!=last()">-</xsl:if>
</xsl:for-each>
			 </xsl:with-param>
                     </xsl:call-template>
              </select>
</xsl:template>

if x is the parent of your target:row elements.


In XSLT2 it's just

<x xmlns:target="t">

       <target:row Category='A-B-C-D'/>
       <target:row Category='A-B'/>
       <target:row Category='A-C-D'/>
       <target:row Category='C'/>
       <target:row Category='B-C-D'/>
       <target:row Category='A-t'/>
</x>




<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:target="t" >

<xsl:output indent="yes"/>

<xsl:template match="x">
  <xsl:for-each select="distinct-values(target:row/tokenize(@Category,'-'))">
   <option><xsl:value-of select="."/></option>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

$ saxon8 spl.xml spl.xsl
<?xml version="1.0" encoding="UTF-8"?>
<option xmlns:target="t">A</option>
<option xmlns:target="t">B</option>
<option xmlns:target="t">C</option>
<option xmlns:target="t">D</option>
<option xmlns:target="t">t</option>

Current Thread