Subject: Re: [xsl] value of xsl:param in xsl:sort From: "Kunal H. Parikh" <kunal@xxxxxxxxxx> Date: Thu, 14 Feb 2002 16:45:11 +1100 |
Hi Peter ! Thanks for your help. I am pasting my code here for your review: ================================================== <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="sortCriteria">TAP/TutorialList/Tutorial/AuthorList/Author/Name</xsl:pa ram> <xsl:template match="/"> <html> <head> <title> This StyleSheet sorts the tutorials by the Author Name in ascending order</title> </head> <body> <table border="1" cell-spacing="2" cell-padding="2"> <xsl:for-each select="TAP/TutorialList/Tutorial"> <xsl:sort select="$sortCriteria" order="ascending"></xsl:sort> <tr> <td> <a> <xsl:attribute name="href">Tutorials/Tutorial<xsl:value-of select="SequenceID" />.html</xsl:attribute> <xsl:value-of select="Title/Main"></xsl:value-of> </a> </td> <td> <xsl:for-each select="AuthorList/Author"> <xsl:value-of select="Name"></xsl:value-of> <br></br> </xsl:for-each> </td> <td> <xsl:value-of select="Date/Created"></xsl:value-of> </td> <td> <xsl:value-of select="DifficultyLevel"></xsl:value-of> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> ================================================== Peter, I did not exactly understand what you said, but I thinkthe reason for that is my lack of knowledge about XML and XSL. So, can you please explain the concept using the example ?. Thanks. Also Peter, it appears that you are very familiar with XML. Caould you please point me to tutorials that you think would help ? Thanks, Kunal ----- Original Message ----- From: "Peter Davis" <pdavis152@xxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Thursday, February 14, 2002 4:22 PM Subject: Re: [xsl] value of xsl:param in xsl:sort > I assume that your xsl:sort is a child of a xsl:for-each or an > xsl:apply-templates, and that the xsl:param is a child of an xsl:template or > the top level, and that the xsl:param and xsl:sort are not together like you > pasted, or else your stylesheet shouldn't work at all. If that's not the > case, then look at that first. > > The problem is that xsl:sort converts the result of its select attribute with > the string() function and uses that as the sort key. So what you have is > string($sortByElement), which is the same for every element since the value > of $sortByElement never changes. Since all the sort keys are identical, the > sort has no effect. > > Specifying the path directly would have a different result for each element > in the sorted list. > > Unfortunately you can't use a param or variable like this, since its value > never changes. If you need to use a complete XPath expression dynamically, > look for an "evaluate" extension function for your specific processor. > Otherwise, you are stuck with matching the name of a single child element, as > someone else posted, by doing *[name() = $sortByElement]. > > On Wednesday 13 February 2002 20:41, Kunal H. Parikh wrote: > > Hi ! > > > > ======================== > > <xsl:param name="sortByElement">AuthorList/Author/Name</xsl:param> > > <xsl:sort select="$sortByElement" order="ascending"></xsl:sort> > > ======================== > > > > The above code does not seem to be replacing the $sortByElement for the > > parameter. > > > > But, if I replace "$sortByElement" with "AuthorList/Author/Name", > > everything works out just fine. > > > > Can someone please suggest what mistake I am making ? > > > > > > > > TIA, > > > > Kunal > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > -- > Peter Davis > It is very difficult to prophesy, especially when it pertains to the future. > > 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] value of xsl:param in xsl, Peter Davis | Thread | Re: [xsl] value of xsl:param in xsl, Jeni Tennison |
Re: [xsl] value of xsl:param in xsl, Peter Davis | Date | [xsl] How to get the preceding-sibl, Mailer Mailer |
Month |