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

Group by node in XSL

Status
Not open for further replies.

jdbolt

Programmer
Aug 10, 2005
89
CA
I was wondering if there was a way to group by a certain node in xml?

Here is my XML document:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<root type='resources'>
<child>
<modifier>DMPORTLS</modifier>
<url>[URL unfurl="true"]http://www.slashdot.org</url>[/URL]
<category>Test1</category>
<categorydescription>This category will be useful</categorydescription>
<linkdescription>All things tech...</linkdescription>
<displaytext>News for nerds, stuff that matters</displaytext>
<description>All things tech...</description>

<cascadelinks>1</cascadelinks>
</child>
<child>
<modifier>BBCI</modifier>
<url>[URL unfurl="true"]http://www.foo.com</url>[/URL]
<category>foo</category>
<categorydescription>The foobar category</categorydescription>
<linkdescription>This is the BBCI Link</linkdescription>
<displaytext>BBCI Link</displaytext>
<description>This is the BBCI Link</description>

<cascadelinks>1</cascadelinks>
</child>
<child>
<modifier>DMPORTLS</modifier>
<url>foo.com</url>
<category>foo</category>
<categorydescription>The foobar category</categorydescription>
<linkdescription>description</linkdescription>
<displaytext>fooDisplay</displaytext>
<description>description</description>

<cascadelinks>0</cascadelinks>
</child>
</root>

So far I have the following XSL document:

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]

	<xsl:template match="/">
	
		<table id="removePortal" class="">
			<tr>
				<td><h2>Please select the category:</h2></td>
			</tr>
			<tr>
				<td>
					<select size="7" class="removeLink">
						<xsl:attribute name="onchange">
							displayRemoveLinkDisplayText('BBCI', this.options[this.selectedIndex].value);
						</xsl:attribute>		
						<xsl:for-each select="root/child">
							<xsl:sort select="modifier" order="ascending"/>
							<option>
								<xsl:attribute name="value">
									<xsl:value-of select="category" />
								</xsl:attribute>			
								<xsl:value-of select="category" />				
							</option>
						</xsl:for-each>
					</select>
				</td>
			</tr>
		</table>
		
	</xsl:template>

</xsl:stylesheet>

But is displays some categories twice, is there a way to do this so that it only displays a category once?

Thanks alot,

Jon
 
Didn't I show you how to do this before?
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="/">
    <table id="removePortal" class="">
      <tr>
        <td>
          <h2>Please select the category:</h2>
        </td>
      </tr>
      <tr>
        <td>
          <select size="7" class="removeLink" onchange="displayRemoveLinkDisplayText('BBCI', this.options[this.selectedIndex].value);">
            <xsl:for-each select="root/child[not(category = preceding-sibling::child/category)]">
              <xsl:sort select="modifier" order="ascending"/>
              <option value="{category}">
                <xsl:value-of select="category"/>
              </option>
            </xsl:for-each>
          </select>
        </td>
      </tr>
    </table>
  </xsl:template>
</xsl:stylesheet>
For more on grouping, this is a good link:


Jon

"I don't regret this, but I both rue and lament it.
 
No, you helped me with something similar, but I couldnt make it work for this xml doc, Im such a n00b :), thanks for all your help though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top