Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl: avoiding repeating values in an option box 1

Status
Not open for further replies.

YYYYUU

Programmer
Dec 13, 2002
47
GB
I have xml as such:

<department>
<export>shoes</export>
<export>beds</export>
<export>blankets</export>
<export>cars</export>
<export>beds</export>
</department>

Using xml above is it possible to make a drop down menu of values in <export> but where a value is repeated, for this to only appear one.

i want:

drop down:
shoes
beds
blankets
cars

NOT:
shoes
beds
blankets
cars
beds

I have tried:

<xsl:template match=&quot;//document/&quot;>
<xsl:variable name=&quot;fred&quot;></xsl:variable>
<xsl:if test=&quot;not(fred='export')&quot; >
<option value=&quot;{export}&quot;><xsl:value-of select=&quot;export&quot;/></option>
</xsl:if>
fred={export}
</xsl:template>

I know my syntax is poor but could someone please help.


 
Check if the current node doesn't match a preceding node:
Code:
  <xsl:template match=&quot;department&quot;>
    <xsl:for-each select=&quot;export&quot;>
      <xsl:sort select=&quot;.&quot;/>
      <xsl:if test=&quot;not(.=preceding::export)&quot;>
        <option value=&quot;{.}&quot;>
          <xsl:value-of select=&quot;.&quot;/>
        </option>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top