XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 20th, 2004, 07:12 AM
Pastoortje Pastoortje is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 4 Pastoortje User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Sort on a parameter

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.

Reply With Quote
  #2  
Old January 20th, 2004, 11:13 PM
imillar imillar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Toronto Canada
Posts: 7 imillar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to imillar
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...

Reply With Quote
  #3  
Old January 21st, 2004, 02:09 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 305 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 7 h 17 m 54 sec
Reputation Power: 7
>> <xsl:variable name="sortOn"
select="bibtex:file/bibtexutstyle/bibtexutsort"/>
>> <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/bibtexutstyle/bibtexutsort'" />

which not the same as the XPath expression:

<xsl:sort select="bibtex:file/bibtexutstyle/bibtexutsort" />

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

Reply With Quote
  #4  
Old January 21st, 2004, 02:11 PM
fpmurphy fpmurphy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: USA
Posts: 305 fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level)fpmurphy User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 7 h 17 m 54 sec
Reputation Power: 7
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

Reply With Quote
  #5  
Old January 22nd, 2004, 02:22 AM
Pastoortje Pastoortje is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: The Netherlands
Posts: 4 Pastoortje User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks everybody for your suggestions.

I went for the suggestion from imillar and this works okay.

Reply With Quote
  #6  
Old September 3rd, 2004, 01:10 PM
eSouL eSouL is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 eSouL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!!

Reply With Quote
  #7  
Old September 3rd, 2004, 01:28 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
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

Reply With Quote
  #8  
Old September 4th, 2004, 01:46 AM
eSouL eSouL is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 eSouL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by NotGoddess
Try here:
http://www.gingerall.org/ga/html/sxp/sparse-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

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?

Reply With Quote
  #9  
Old September 4th, 2004, 10:38 AM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Quote:
Originally Posted by eSouL
Question is, how do i write a custom function in a .XSL sheet?


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?

Reply With Quote
  #10  
Old September 4th, 2004, 12:47 PM
eSouL eSouL is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 eSouL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Sort on a parameter


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT