问题:
我正在尝试根据查询字符串上传递的参数创建一个新的 XML(过滤的 XML)。
URL 示例:search_advanced.xhtml?department=CHEM&offered=Y&level=P
例如,如果上面的查询字符串被传递,我希望过滤后的 XML 只显示那些包含
- 等于 CHEM 的部门 (fas_courses/course/department/@code)
- 提供的代码等于 Y (fas_course/course/@offered)
- 一个级别代码等于 P (fas_course/course/@offered)
下面是我一直在处理的原始 XML 文件和 XSLT 文件。感谢您的任何建议。
原始 XML
<fas_courses>
<course acad_year="2012" cat_num="85749" offered="N" next_year_offered="2013">
<term term_pattern_code="4" fall_term="Y" spring_term="Y">full year</term>
<department code="VES">
<dept_long_name>Department of Visual and Environmental Studies</dept_long_name>
<dept_short_name>Visual and Environmental Studies</dept_short_name>
</department>
<course_group code="VES">Visual and Environmental Studies</course_group>
<title>Critical Media Practice: Non Fiction Filmmaking Workshop</title>
<course_type>Studio</course_type>
<course_level code="G">Graduate Course</course_level>
<description>A graduate workshop for Film Study Center non-fiction film and video projects.</description>
</course>
<course>
.....
</course>
<course>
.....
</course>
</fas_courses>
XSL 文件
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:param name="url"/>
<xsl:param name="querystring"/>
<xsl:param name="baselink"/>
<xsl:param name="department" select="'All'"/>
<xsl:param name="course_group" select="'All'"/>
<xsl:param name="description" select="'All'"/>
<xsl:param name="level" select="'All'"/>
<xsl:param name="term" select="'All'"/>
<xsl:param name="offered" select="'All'"/>
<xsl:template match="/">
<fas_courses>
<xsl:apply-templates />
</fas_courses>
</xsl:template>
<xsl:template match="//course
[
($department = '' or $department = 'All' or department/@code = $department)
and
($course_group = '' or $course_group = 'All' or course_group/@code = $course_group)
and
($description = '' or $description = 'All' or description = $description)
and
($level = '' or $level = 'All' or course_level/@code = $level)
and
($term = '' or $term = 'All' or term/@term_pattern_code = $term)
and
($offered = '' or $offered = 'All' or @offered = $offered)
]">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>