I am trying to filter the XML by what I get in a parameter. What is the correct sintax to match on only those courses that have dep_code equal to 'something' or in this case $department???
XML STRUCTURE IS
<course>
<dep_code></dep_code>
<catalog_number></catalog_number>
<course_group></course_group>
<term></term>
<offered></offered>
<course_type></course_type>
<course_level></course_level>
<title></title>
<course_number></course_number>
<meeting_text></meeting_text>
<faculty_text></faculty_text>
<description></description>
<prerequisites></prerequisites>
</course>
Parameter defined
<xsl:param name="department" select="'All'" />
Code I have tried I have tried this:
<xsl:template match="course/dep_code/{$department}">
Also this:
<xsl:template match="course/dep_code/$department">
<xsl:template match="course/dep_code eq $department">
I I keep on getting syntactical errors like the following:
Thanks in advance
Sample XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<courses>
<course>
<dep_code>not_it</dep_code>
<catalog_number></catalog_number>
<prerequisites></prerequisites>
</course>
<course>
<dep_code>something</dep_code>
<catalog_number></catalog_number>
<prerequisites></prerequisites>
</course>
</courses>
Sample XSLT
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<th>dep_code</th>
</tr>
<xsl:for-each select="courses/course">
<xsl:if test="dep_code[text()='something']">
<tr>
<td><xsl:value-of select="dep_code"/></td>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Result
<html>
<body>
<table border="1">
<tr><th>dep_code</th></tr>
<tr><td>something</td></tr>
</table>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With