XSLT sorting

Discussion in 'XML' started by bcochofel, Dec 11, 2006.

  1. bcochofel

    bcochofel Guest

    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>
    --------------------------------------------------------------------------
    
     
    bcochofel, Dec 11, 2006
    #1
    1. Advertising

  2. bcochofel wrote:

    > 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.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 11, 2006
    #2
    1. Advertising

  3. bcochofel

    bcochofel Guest

    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>...

    On Dec 11, 4:55 pm, Martin Honnen <> wrote:
    > bcochofel wrote:
    > > 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.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    bcochofel, Dec 11, 2006
    #3
  4. bcochofel wrote:
    > 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>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 11, 2006
    #4
  5. bcochofel

    bcochofel Guest

    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...

    On Dec 11, 5:33 pm, Martin Honnen <> wrote:
    > bcochofel wrote:
    > > 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>
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    bcochofel, Dec 11, 2006
    #5
  6. bcochofel wrote:
    > 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 11, 2006
    #6
  7. bcochofel

    bcochofel Guest

    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.

    On Dec 11, 5:41 pm, Martin Honnen <> wrote:
    > bcochofel wrote:
    > > 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.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    bcochofel, Dec 11, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Fitzgerald
    Replies:
    6
    Views:
    732
    Wired Earp
    Oct 3, 2003
  2. Replies:
    2
    Views:
    1,438
    James Kanze
    Jul 6, 2010
  3. Jason
    Replies:
    0
    Views:
    390
    Jason
    Oct 4, 2006
  4. Tom Kirchner

    sorting by multiple criterias (sub-sorting)

    Tom Kirchner, Oct 11, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    476
    Michael Budash
    Oct 11, 2003
  5. Íéêüëáïò Êïýñáò

    Sorting a set works, sorting a dictionary fails ?

    Íéêüëáïò Êïýñáò, Jun 10, 2013, in forum: Python
    Replies:
    12
    Views:
    161
    Ulrich Eckhardt
    Jun 10, 2013
Loading...

Share This Page