Subject: RE: [xsl] filter based on parameter, not getting it. From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Sat, 21 Sep 2002 12:25:44 +0100 |
Oh, dear, you are getting muddled... <xsl:template name="test" match="/"> <xsl:param name="filter"/> <xsl:variable name="filter" select="$filter"/> <table> <xsl:for-each select="$filter"> Firstly, it's an error to have a variable and a param with the same name. The XSLT processor should throw this out. It's also pointless in this case, since you are trying to give them the same value. You don't say what the supplied value of the parameter $filter is, but from the error message it seems obvious that it's a string. <xsl:for-each> can't iterate over a string, it can only iterate over a node-set. Perhaps $filter is a string that contains an XPath expression? In that case, you haven't understood any of the helpful responses you have received on this thread. You can't, in standard XSLT 1.0, construct XPath expressions on the fly from strings. Some XSLT processors have an xx:evaluate() extension that allows you to do it. Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of > Carter, Will > Sent: 20 September 2002 23:21 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] filter based on parameter, not getting it. > > > okay, here is my attempt...not working...very frustrating. > > my error: Can not convert #STRING to a NodeList! > > <xsl:param name="filterparam"/> > > <!-- try to take the if condition out of the test template > --> <xsl:template match="/"> <xsl:choose> > <xsl:when test="string-length($filterparam) = 0"> > <xsl:call-template name="test"> > <!-- trying to call the test template > with no filter --> > <xsl:with-param name="filter" > select="//person"></xsl:with-param> > </xsl:call-template> > </xsl:when> > <xsl:otherwise> > <xsl:call-template name="test"> > <!-- trying to call the test template > with the filterparam as the filter --> > <xsl:with-param name="filter" > select="//person[cat = $filterparam]"></xsl:with-param> > </xsl:call-template> > </xsl:otherwise> > </xsl:choose> > </xsl:template> > > > <xsl:template name="test" match="/"> > <xsl:param name="filter"/> > <xsl:variable name="filter" select="$filter"/> > <table> > <xsl:for-each select="$filter"> > <tr> > <td><xsl:value-of select="cat"/></td> > <td><xsl:value-of select="dog"/></td> > <td><xsl:value-of select="fish"/></td> > </tr> > </xsl:for-each> > </table> > </xsl:template> > > > > -----Original Message----- > From: Passin,Thomas B. (Tom) [mailto:tpassin@xxxxxxxxxxxx] > Sent: Friday, September 20, 2002 3:27 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] filter based on parameter, not getting it. > > > [Carter, Will] > > > This code doesn't work: > > > <table> > > <xsl:for-each select="$filter"> > > <!--=============================================== > Here is the problem. The variable is out of scope - it > is only in scope in your xsl:when or xsl:otherwise element. > Therfore the variable does not exist for the code below. > ==================================================--> > > > > <tr> > > <td><xsl:value-of select="cat"/></td> > > <td><xsl:value-of select="dog"/></td> > > <td><xsl:value-of select="fish"/></td> > > </tr> > > </xsl:for-each> > > </table> > > --------------------------------------------------------- > > Restructure your stylesheet so that you call a named template (or > apply-templates) to create the table cells, and pass in the > $filter variable as a parameter to the template. > > Cheers, > > Tom P > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] filter based on parameter, Marrow | Thread | RE: [xsl] filter based on parameter, Carter, Will |
RE: [xsl] Calling a java function a, Michael Kay | Date | Re: Re: [xsl] Getting desired node , alex ek |
Month |