Hi,
I have an XML like this:
<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'/>
with a combination of values separated by '-'. I need to populate a listbox
with unique values:
A
B
C
D
I tried to save in a variable what was already processed and skip it in case
was found but the 'seen' variable is clean'd up at the second round:
<xsl:key name='Category' match='xml/target' use='@Category'/>
<xsl:variable name='seen' select="''"/>
<xsl:template name="my_templ_1">
<SELECT NAME="X" MULTIPLE="MULTIPLE">
<xsl:for-each select='$Rowset[generate-id() =
generate-id(key("Category", @Category))]'>
<xsl:call-template name="Split">
<xsl:with-param name="strInput" select="@Category"/>
</xsl:call-template>
</xsl:for-each>
</SELECT>
</xsl:template>
<xsl:template name="Split">
<xsl:param name="strInput"/>
<xsl:param name="strDelimiter" select="'-'"/>
<xsl:param name="processed"/>
<xsl:variable name="strNextItem"
select="substring-before($strInput,$strDelimiter)"/>
<xsl:variable name="strOutput"
select="substring-after($strInput,$strDelimiter)"/>
<xsl:variable name="seen" select="concat($strNextItem,',',$processed)"/>
<xsl:choose>
<xsl:when test='contains($strInput,$strDelimiter) and
not(contains($strInput,$seen))'>
<xsl:element name='OPTION'>
<xsl:value-of select="$strNextItem"/>
</xsl:element>
<xsl:call-template name="Split">
<xsl:with-param name="strInput" select="$strOutput"/>
<xsl:with-param name="strDelimiter" select="$strDelimiter"/>
<xsl:with-param name="processed" select="$seen"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test="not(contains($strInput,$seen))">
<xsl:element name='OPTION'>
<xsl:value-of select="$strInput"/>
</xsl:element>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Do you have a more elegant way?
Thank you.
Carlos
------------------------------------------------------
Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom
http://click.libero.it/infostrada07dic06
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--