|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi there,
Part of my xml-document looks like this: <bibtex:file> <bibtex:outstyle> <bibtex:outsort>*/bibtex:title</bibtex:outsort> </bibtex:outstyle> <bibtex:entry id="articlereq"> <bibtex:article> <bibtex:author>Author</bibtex:author> <bibtex:title>Title</bibtex:title> </bibtex:article> </bibtex:entry> ... </bibtex:file> In my xsl-document I have: <xsl:variable name="sortOn" select="bibtex:file/bibtex:outstyle/bibtex:outsort"/> Now, I want to sort my entries on outsort. I tried this using: <xsl:apply-templates select="bibtex:entry"> <xsl:sort select="$sortOn"/> </xsl:apply-templates> But this doesn't work. Just using xsl:value-of to discover if the value is correct works perfectly, but when I use it in xsl:sort it doesn't work. Now I know that I could just place it in my xsl-document, but my sorting element is ment to be felxible. I did try that, just to check if my statement is correct and then it does work. |
|
#2
|
|||
|
|||
|
Hello,
Unfortunately, I have never been able to use variables within xsl:sort, apply-templates, or call-templates. This would increse the power of XSLT tremendously. One way to make it more dynamic would be to have a choose statement that has several cases each with different sort statements: <xsl:choose> <xsl:when test="case_a"> <xsl:call-template name="sort1" /> </xsl:when> <xsl:when test="case_b"> <xsl:call-template name="sort2" /> </xsl:when> </xsl:choose> This has helped me in the past...Hope it helps you... |
|
#3
|
|||
|
|||
|
>> <xsl:variable name="sortOn"
select="bibtex:file/bibtex utstyle/bibtex utsort"/>>> <xsl:apply-templates select="bibtex:entry"> >> <xsl:sort select="$sortOn"/> >> </xsl:apply-templates> This is not directly supported in XSLT1. The problem is that you are actually getting a text string: <xsl:sort select="'bibtex:file/bibtex utstyle/bibtex utsort'" />which not the same as the XPath expression: <xsl:sort select="bibtex:file/bibtex utstyle/bibtex utsort" />There are a couple of workarounds. One way is to use an extension function that converts a text string into an XPath expression. For example, with SAXON you could use the evaluate() function. - Finnbarr |
|
#4
|
|||
|
|||
|
Sorry about the smilies!
>> <xsl:variable name="sortOn" select="bibtex:file/bibtex:outstyle/bibtex:outsort"/> >> <xsl:apply-templates select="bibtex:entry"> >> <xsl:sort select="$sortOn"/> >> </xsl:apply-templates> This is not directly supported in XSLT1. The problem is that you are actually getting a text string: <xsl:sort select="'bibtex:file/bibtex:outstyle/bibtex:outsort'" /> which not the same as the XPath expression: <xsl:sort select="bibtex:file/bibtex:outstyle/bibtex:outsort" /> There are a couple of workarounds. One way is to use an extension function that converts a text string into an XPath expression. For example, with SAXON you could use the evaluate() function. - Finnbarr |
|
#5
|
|||
|
|||
|
Thanks everybody for your suggestions.
I went for the suggestion from imillar and this works okay. |
|
#6
|
|||
|
|||
|
hi.
sorry to bring up this old thread. but i've search for hours and couldn't find anything useful. my problem is exactly like what described by fpmurphy, except i'm using the Sablotron processor. how do i mimic the saxon:evaluate() behaviour in Sablotron? Thanks for helping!! |
|
#7
|
||||
|
||||
|
Try here:
http://www.gingerall.org/ga/html/sx...e-frameset.html or more generally here: http://www.gingerall.org If that doesn't help you, there's an older post that lists old work-arounds: http://www.xslt.com/html/xsl-list/2002-06/msg00987.html |
|
#8
|
|||
|
|||
|
Quote:
Sorry i'm a newbie at XSLT, yet i need to do this for my FYP. It seems the only way is to write my own evaluate function for sablotron. Question is, how do i write a custom function in a .XSL sheet? |
|
#9
|
||||
|
||||
|
Quote:
xsl:function is a XSL 2.0 addition. http://www.w3.org/TR/xslt20/#element-function There is an example there as well. I should mention that Sablotron seems to choke on anything but a numeric xsl:sort, at least for me. I and others might be able to help you more if you could post a link or samples of your xml/xsl. There may be another way to accomplish what you want. Did you try the other solutions posted here and in the links? |
|
#10
|
|||
|
|||
|
My application has nothing to do with sorting. I need to convert an OpenOffice.org generated file (content.xml extracted from the sxw archieve) to HTML+CSS output.
I have many sets of the following code chunk, passing parameter to a template 'pass-css': <xsl:call-template name="pass-css"> <xsl:with-param name="attrib" select="'@style:horizontal-pos'"/> ... (+ other params) </xls:call-template> My template is as follow: <xsl:template name="pass-css"> <xsl:param name="attrib"/> <xsl:param name="css" select="substring-after($attrib,':')"/> ... (other params) <xsl:param name="output" select="evaluate($attrib)"/> (and in somewhere down the template i will apply this:) <xsl:value-of select="$output"/> </xsl:template> As such I need to evaluate the $attrib string as an XPath for it to work. Any ideas? Thanks a lot!! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Sort on a parameter |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|