Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:56:15+00:00 2026-06-04T14:56:15+00:00

My code below seems logical however i don’t know why the sorting doesn’t work

  • 0

My code below seems logical however i don’t know why the sorting doesn’t work with the error “Variable or parameter ‘sort’ is undefined.’“? Im suspecting there are something wrong with declaring param in xsl. Could anyone point my mistake? thanks

java code to pass parameter

String sort = "rating";
transformer.setParameter("sort", sort); /It will control the sort in xsl

xml file

    <?xml version="1.0" ?>

<cd>
  <title>A Funk Odyssey</title>
  <artist>Jamiroquai</artist>

  <tracklist>
    <track id="1">
      <title>Feels So Good</title>
      <time>4:38</time>
      <rating>2</rating>
    </track>

    <track id="2">
      <title>Little L</title>
      <time>4:10</time>
      <rating>5</rating>
    </track>

    <track id="3">
      <title>You Give Me Something</title>
      <time>5:02</time>
      <rating>3</rating>
    </track>

    <track id="4">
      <title>Corner of the Earth</title>
      <time>3:57</time>
      <rating>1</rating>
    </track>
  </tracklist>


</cd>

This is my xsl

            <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
    <xsl:param name="sort" select="title"/>
    <xsl:template match="/">
        <table border="1">
            <thead>
                <tr>
                    <th><a href="#">Title</a></th>
                    <th><a href="#">Time</a></th>
                    <th><a href="#">Rating</a></th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="cd/tracklist/track">
                    <xsl:sort select="$sort"/>
                    <tr>
                        <td><xsl:value-of select="title" /></td>
                        <td><xsl:value-of select="time" /></td>
                        <td><xsl:value-of select="rating" /></td>
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>
</xsl:stylesheet>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:56:16+00:00Added an answer on June 4, 2026 at 2:56 pm

    In your xsl:param declaration you are trying to default to $sort which is not defined at the time xsl:param is evaluated. It does look like a reference to itself.

    If you don’t need a default then just change your parameter declaration to:

    <xsl:param name="sort"/>
    

    or default to a string value:

    <xsl:param name="sort" select="'title'"/>
    

    or

    <xsl:param name="sort">title</xsl:param>
    

    That said, we have only addressed the parameter declaration issue. Now on to sorting. The xsl:sort needs an expression, it won’t convert a string value into XPath like you expect it to.

    Here’s a solution: Using Variables in <xsl:sort select=""/>.

    You would basically do something like:

    <xsl:sort select="*[name() = $sort]"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The below code seems like it should work; however, the blob in the database
The code below doesn't seem to work or find anything on an array. I'm
I am relatively new to jQuery but the below code seems logical but is
The code below seems not to be inserting the parameter value to the query
I want to update two tables at once. The code below seems to work
Code below doesn't seems clean. Any suggestion to improve the code? <li @if(ViewData[pagename].ToString()==Business details){
The pattern below seems to work in regex editors, but it doesn't work in
I've stress tested the code below and it seems to work fine - what
PART 1: The below code seems to work fine, but there must be a
i use below code - Just try again. - to prevent deadlock. it seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.