Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:25:00+00:00 2026-06-15T15:25:00+00:00

QUESTION: I am trying to create a new XML(filtered XML) depending on the parameters

  • 0

QUESTION:

I am trying to create a new XML(filtered XML) depending on the parameters passed on the query string.

URL Example: search_advanced.xhtml?department=CHEM&offered=Y&level=P

For instance, if the query string above is passed, I will like the filtered XML to only show those courses that contain

  • A department that are equal to CHEM (fas_courses/course/department/@code)
  • An offered code equal to Y (fas_course/course/@offered)
  • A Level code equal to P (fas_course/course/@offered)

the original XML file and the XSLT file I have been working on are below. Thanks for any suggestions.

THE ORIGINAL 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>

THE XSL FILE

<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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:25:01+00:00Added an answer on June 15, 2026 at 3:25 pm

    If you can preprocess the query string, you can pass the parts as parameters to the transformation.

    Based on the parameters you’ve set up, I’m assuming you can’t do that, so the code below parses one passed-in parameter (the URL) to derive each parameter. Note that the method I’ve used assumed one change to your query string: that it can end with an ampersand. If it cannot, you’ll need a slightly more sophisticated string parsing method. FunctX has one that should work: substring-before-if-contains. Otherwise, the last item in your query will end up as an empty string.

    The following XSL provides the desired result on the following XML (returns only cat number 85753) when run with your sample URL snippet passed in as the url param (with the final ampersand added).

    Note the empty course template at the end, which allows non-matching courses to be skipped. Without that, you’ll see the text nodes from those non-matching courses.

    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="CHEM">
                <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 acad_year="2012" cat_num="85751" offered="Y" next_year_offered="2013">
            <term term_pattern_code="4" fall_term="Y" spring_term="Y">full year</term>
            <department code="CHEM">
                <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 acad_year="2012" cat_num="85753" offered="Y" next_year_offered="2013">
            <term term_pattern_code="4" fall_term="Y" spring_term="Y">full year</term>
            <department code="CHEM">
                <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="P">Graduate Course</course_level>
            <description>A graduate workshop for Film Study Center non-fiction film and video projects.</description>
        </course>
        <course acad_year="2012" cat_num="85755" offered="N" next_year_offered="2013">
            <term term_pattern_code="4" fall_term="Y" spring_term="Y">full year</term>
            <department code="CHEM">
                <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>
    </fas_courses>
    

    XSL:

    <?xml version="1.0" encoding="UTF-8"?>
     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
       <xsl:param name="url"/>
       <xsl:param name="querystring" select="substring-after($url, '?')"/>
       <xsl:param name="baselink" select="substring-before($url, '?')"/>
       <xsl:param name="department" select="substring-before(substring-after($querystring, 'department='), '&amp;')"/>
       <xsl:param name="course_group" select="substring-before(substring-after($querystring, 'course_group='), '&amp;')"/>
       <xsl:param name="description" select="substring-before(substring-after($querystring, 'description='), '&amp;')"/>
       <xsl:param name="level" select="substring-before(substring-after($querystring, 'level='), '&amp;')"/>
       <xsl:param name="term" select="substring-before(substring-after($querystring, 'term='), '&amp;')"/>
       <xsl:param name="offered" select="substring-before(substring-after($querystring, 'offered='), '&amp;')"/>
    
        <xsl:template match="/">
            <xsl:apply-templates select="fas_courses"/>
        </xsl:template>
    
        <xsl:template match="fas_courses">
            <xsl:copy>
                 <xsl:apply-templates select="course"/>
            </xsl:copy>
        </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:template match="course"/> 
        </xsl:stylesheet>
    

    Hope that is helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new in xml, sorry for the dumb question. I'm trying to create xsl
This is just a simple question. I was trying to create a new object
I am new to java and I am trying to create an XML document
Question I'm trying to create a basic wxWidgets program with a text entry box,
I am trying to create a question and answers page. In which I am
After trying a lot i decided to ask question on stackoverflow, I create a
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
I'm trying to create a xml file for Flam3 that contains multiple forms. I'm
I am starting a new project trying to create a web application for an
I'm trying to retrieve an XML stream from a URL. For most URLs my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.