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

Split and Found unique values

Subject: Split and Found unique values
From: "cruscio\@libero\.it" <cruscio@xxxxxxxxx>
Date: Thu, 7 Dec 2006 15:00:32 +0100
split value in xsl
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

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.