XSLT sorting

B

bcochofel

I'm using xsl to list an xml file that contains something like: sites,
tag and weight.

I'm listing this in a table with the following titles: | URL | TAG |
WEIGHT (each title his a link)

What I want is when someone clicks a title chooses the sorting option,
if this is the actual sorting option then reverses the order. Can I do
this? How?

Here's an example:
Code:
---------------------------------------------------------------------------------
    <sites>
    <!--
	  Site url: required (pattern: (https?|ftp)://.+)
	  Tag name: required
	  Tag weight: integer optional
    -->
      <site url="http://www.google.com">
        <tag name="pesquisa" weight="30" />
        <tag name="procura" weight="30" />
      </site>
      <site url="http://www.google.com/webhp?complete=1">
        <tag name="ajax" weight="25" />
        <tag name="pesquisa" weight="30" />
        <tag name="procura" weight="30" />
      </site>
      <site url="https://webmail.fe.up.pt">
        <tag name="email" weight="20" />
        <tag name="feup" weight="20" />
      </site>
    </sites>
 
M

Martin Honnen

bcochofel said:
What I want is when someone clicks a title chooses the sorting option,
if this is the actual sorting option then reverses the order. Can I do
this? How?

Your XSLT probably creates a HTML table. To sort that table you can use
client-side script (JavaScript) if available. You can also use
client-side XSLT to sort if available although then you have to use
script too to run the transformation. A robust solution that works
independent of the browsers XSLT and script support will need to sort
the table server-side meaning a click on that table header will send a
request to the server to do the sorting and send a new document with a
sorted table back.
 
B

bcochofel

Well, I'm using Perl CGI to generate the XML on the server-side. On the
XML I have the query params from the script, so I was wondering if I
can use this params to sort within the XSL?
Also, I can I create an url with the value of some elements from my
XML?
Something like (on my xsl file), <a href="listsites.cgi?field=<xml
element value here>&sort=<xml element value here>">sites</a>...
 
M

Martin Honnen

bcochofel said:
Well, I'm using Perl CGI to generate the XML on the server-side. On the
XML I have the query params from the script, so I was wondering if I
can use this params to sort within the XSL?

Do you run the XSLT transformation on the server with Perl too? Or do
you rely on the browser doing the XSLT transformation?
Also, I can I create an url with the value of some elements from my
XML?
Something like (on my xsl file), <a href="listsites.cgi?field=<xml
element value here>&sort=<xml element value here>">sites</a>...

Use attribute value templates e.g.
<a href="listsites.cgi?field={element-name}&amp;sort={element2-name}">
or xsl:attribute
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="concat('listsites.cgi?field=', element-name,
'&amp;sort=', element2-name)"/>
</xsl:attribute>
</xsl:element>
 
B

bcochofel

I'm using HTML::Template to generate my XML file (template.xml) Under
that template I have a reference for a local XSL. This is the only way
I know... I'm new to XML...
 
M

Martin Honnen

bcochofel said:
I'm using HTML::Template to generate my XML file (template.xml) Under
that template I have a reference for a local XSL. This is the only way
I know... I'm new to XML...

I don't use Perl, you will have to ask in a Perl group or wait whether
someone here comes along that can help with that Perl package.
 
B

bcochofel

It's the same as having a XML file and ref to a local XSL.
The Perl package creates the XML file and on the browser apears the
context...
If I don't put the line: <?xml-stylesheet type="text/xml"
href="RR.xsl"?>
I get pure XML on the browser.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top