[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] Split and Found unique values
Subject: [xsl] Split and Found unique values From: "cruscio\@libero\.it" <cruscio@xxxxxxxxx> Date: Thu, 7 Dec 2006 15:00:32 +0100 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] XSL Formatter V4.1 Release In, Keiko Hiraide | Thread | Re: [xsl] Split and Found unique va, David Carlisle |
Re: [xsl] Searching in Sub-children, David Carlisle | Date | Re: [xsl] Split and Found unique va, David Carlisle |
Month |
Keywords