Jump to content

Using XSL to filter an XML document


John Smart

Recommended Posts

Hi chaps.I have a question regarding XSL. Basically, I have an xml file containing records of occupations (occupation name, category, and links to further information).I am using html within an xsl file to display the list, and it all works fine. There are 800 occupations though, so I want to be able to filter them alphabetically, by using input buttons to call in other xsl files, which filter the information (select="occupations/occupation[alpha$eq$'A'] etc). I've left in my onclick as it was (getA.xsl is the xsl file to display everything with A), as whilst this obviously doesn't work now, shows some of my methodI can't work out how to reference the other xsl files from my 'main' xsl file. We did have it working previously using the DATASRC and DATAFLD tags and using some javascript, but that's IE specific I believe, and also had trouble getting links to work correctly that way.Any help would be most appreciated - I'm sure this is fairly straightforward but have been trauling the internet looking for help! I've attached a sample from my xml file (condensed to 1 record for ease), and my xsl file.Thanks,JohnXML:

<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="smallbustrucksoccupations.xsl"?><occupations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SmallBusTrucksOccupations.xsd">  <occupation>	<description>Agricultural Produce Distribution</description>	<term>Unacceptable</term>	<rationale>Distribution</rationale>	<url>/prod/kite/TechContainer.nsf/FreePagesByUNID/7AAACF15BD75D14B802572DD00293416?OpenDocument</url>  </occupation></occupations>

XSL:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><span style="font-family: verdana; font-size: 8pt; font-weight: bold; color: #000098;">OCCUPATIONS LISTINGS</span><br /><br /><input  type="button" style="font-family: verdana; font-size: 11" value="A" onclick="ApplyStyleSheet(getA.xsl);" /><br /><br /><table style="border-style:solid; border-width:1; cellpadding:0; cellspacing:0; border-color:#c0c0c0; font-family:verdana; font-size:8pt;">  <tr style="background-color:#D8EDF1; color:#002b7c; border-style:solid; border-width:1; cellpadding:0; cellspacing:0; border-color:#c0c0c0; font-family:verdana; font-size:8pt;">	<th>Description</th> 	<th>Term</th> 	<th>Rationale</th>   </tr>  <xsl:for-each select="occupations/occupation">  <tr>	<td><xsl:value-of select="description" /></td>	<xsl:choose>	  <xsl:when test="term = 'Acceptable'">		<td style="background-color:#128612; color:#ffffff;"><xsl:value-of select="term" /></td>	  </xsl:when>	  <xsl:when test="term = 'Refer'">		<td style="background-color:#D99918; color:#ffffff;"><xsl:value-of select="term" /></td>	  </xsl:when>	  <xsl:when test="term = 'Unacceptable'">		<td style="background-color:#E83F3F; color:#ffffff;"><xsl:value-of select="term" /></td>	  </xsl:when>	</xsl:choose>	<td><a href="{url}"><xsl:value-of select="rationale" /></a></td>  </tr>  </xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...