using wildcards in a select

Discussion in 'XML' started by Heltende, Mar 9, 2008.

  1. Heltende

    Heltende Guest

    I'm trying to develop a stylesheet that takes a parameter that is used
    to filter the results. It works great *except* for the fact that I
    want one of my options to be a "See All", removing any filters.

    I was hoping that I could do this by setting a parameter to default to
    * and then removing the parameter when the user tries to see all. It
    doesn't work though.

    Here's what I have:


    <xsl:param name="year_filter" select="*"/>
    <xsl:template match="data">
    ....
    <xsl:for-each select="holiday_list/row[year=$year_filter]">
    <xsl:variable name="description" select="description"/>
    ....
    </tr>
    </xsl:for-each>

    The following works:

    <xsl:for-each select="holiday_list/row[year=*]">
    <xsl:variable name="description" select="description"/>
    ....
    </tr>
    </xsl:for-each>

    but I can't figure out how to get year_filter to equal '*'. The
    problem with the first example is clear when I display the value of
    $year_filter. It shows a concatenated list of all of my data.

    I'm an xslt beginner, so if this is a stupid question, I beg your
    forgiveness and patience!

    TIA, Charles
    Heltende, Mar 9, 2008
    #1
    1. Advertising

  2. Heltende wrote:
    > I'm trying to develop a stylesheet that takes a parameter that is used
    > to filter the results. It works great *except* for the fact that I
    > want one of my options to be a "See All", removing any filters.
    >
    > I was hoping that I could do this by setting a parameter to default to
    > * and then removing the parameter when the user tries to see all. It
    > doesn't work though.
    >
    > Here's what I have:
    >
    >
    > <xsl:param name="year_filter" select="*"/>
    > <xsl:template match="data">
    > ...
    > <xsl:for-each select="holiday_list/row[year=$year_filter]">
    > <xsl:variable name="description" select="description"/>
    > ...
    > </tr>
    > </xsl:for-each>
    >
    > The following works:
    >
    > <xsl:for-each select="holiday_list/row[year=*]">
    > <xsl:variable name="description" select="description"/>
    > ...
    > </tr>
    > </xsl:for-each>
    >
    > but I can't figure out how to get year_filter to equal '*'. The
    > problem with the first example is clear when I display the value of
    > $year_filter. It shows a concatenated list of all of my data.


    You might want to set the parameter to an empty string (or the number 0)
    to indicate you don't want to filter and then code e.g.
    <xsl:template match="data">
    <xsl:choose>
    <xsl:when test="$year-filter">
    <xsl:for-each select="holiday_list/row[year=$year_filter]">
    ...
    </xsl:for-each>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:for-each select="holiday_list/row">
    ...
    </xsl:for-each>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>
    If you have a lot of code inside of the for-each then write a named
    template and call that in the for-each to avoid code duplication.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 9, 2008
    #2
    1. Advertising

  3. Heltende

    Heltende Guest

    >
    > You might want to set the parameter to an empty string (or the number 0)
    > to indicate you don't want to filter and then code e.g.
    > <xsl:template match="data">
    > <xsl:choose>
    > <xsl:when test="$year-filter">
    > <xsl:for-each select="holiday_list/row[year=$year_filter]">
    > ...
    > </xsl:for-each>
    > </xsl:when>
    > <xsl:eek:therwise>
    > <xsl:for-each select="holiday_list/row">
    > ...
    > </xsl:for-each>
    > </xsl:eek:therwise>
    > </xsl:choose>
    > </xsl:template>
    > If you have a lot of code inside of the for-each then write a named
    > template and call that in the for-each to avoid code duplication.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/




    Thank you for the rapid response! That code does indeed work. It
    doesn't necessarily "feel" like the most elegant method, but given
    that the "*" seems to have a mind of it's own, depending on context, I
    guess it's the method I'm stuck with! Now to explore the exciting
    world of including named templates!
    Heltende, Mar 9, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Josh Martin
    Replies:
    6
    Views:
    1,859
    Josh Martin
    Nov 23, 2003
  2. Web learner
    Replies:
    0
    Views:
    743
    Web learner
    Apr 18, 2006
  3. Harlin Seritt

    Using wildcards...

    Harlin Seritt, May 2, 2005, in forum: Python
    Replies:
    4
    Views:
    361
    Harlin Seritt
    May 2, 2005
  4. Dipankar
    Replies:
    17
    Views:
    10,720
    Arne Vajhøj
    Aug 1, 2009
  5. William Hudspeth
    Replies:
    2
    Views:
    295
    Fabio FZero
    Mar 15, 2007
Loading...

Share This Page