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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT Grouping

Status
Not open for further replies.

JoeMcGarvey

Programmer
Oct 31, 2002
47
US
Hi,
I am trying to output a "select" field from the sample XML below:

<tree>
<option>Ducks</option>
<option>Cows</option>
<option>Sheep</option>
<option>Sheep</option>
<option>Ducks</option>
<option>Cows</option>
<option>Cows</option>
</tree>

I need to group the option values to produce the sample HTML:

<select name=&quot;animals&quot;>
<option>Cows</option>
<option>Ducks</option>
<option>Sheep</option>
</select>

Can anyone help me with the grouping in XSLT?

I have read about Meunchian Grouping, but am confused...

Thanks!


Joe McGarvey - Web Application Developer
Paragraph, Inc. - Paragraph Publisher -
 
Try this:

<?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; standalone=&quot;yes&quot;?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:eek:utput method=&quot;html&quot; indent=&quot;yes&quot; encoding=&quot;iso-8859-1&quot; omit-xml-declaration=&quot;yes&quot;/>

<xsl:template match=&quot;/tree&quot;>

<HTML>
<BODY>
<TABLE>
<TR>
<TD>
<SELECT>
<xsl:for-each select=&quot;option&quot;>
<xsl:variable name=&quot;pre-option&quot;>
<xsl:for-each select=&quot;preceding-sibling::*&quot;>
<xsl:value-of select=&quot;concat(.,',')&quot;/>
</xsl:for-each>
</xsl:variable>
<xsl:if test=&quot;not(contains($pre-option, . ))&quot;>
<OPTION>
<xsl:value-of select=&quot;.&quot;/>
</OPTION>
</xsl:if>
</xsl:for-each>
</SELECT>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
</xsl:template>

</xsl:stylesheet>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top