using wildcards in a select

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Heltende

    using wildcards in a select

    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_filt er" select="*"/>
    <xsl:template match="data">
    ....
    <xsl:for-each select="holiday _list/row[year=$year_filt er]">
    <xsl:variable name="descripti on" select="descrip tion"/>
    ....
    </tr>
    </xsl:for-each>

    The following works:

    <xsl:for-each select="holiday _list/row[year=*]">
    <xsl:variable name="descripti on" select="descrip tion"/>
    ....
    </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
  • Martin Honnen

    #2
    Re: using wildcards in a select

    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_filt er" select="*"/>
    <xsl:template match="data">
    ...
    <xsl:for-each select="holiday _list/row[year=$year_filt er]">
    <xsl:variable name="descripti on" select="descrip tion"/>
    ...
    </tr>
    </xsl:for-each>
    >
    The following works:
    >
    <xsl:for-each select="holiday _list/row[year=*]">
    <xsl:variable name="descripti on" select="descrip tion"/>
    ...
    </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_filt er]">
    ...
    </xsl:for-each>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:for-each select="holiday _list/row">
    ...
    </xsl:for-each>
    </xsl:otherwise>
    </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

    Comment

    • Heltende

      #3
      Re: using wildcards in a select

      >
      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_filt er]">
      ...
      </xsl:for-each>
      </xsl:when>
      <xsl:otherwis e>
      <xsl:for-each select="holiday _list/row">
      ...
      </xsl:for-each>
      </xsl:otherwise>
      </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!

      Comment

      Working...