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 6830459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:37:13+00:00 2026-05-26T22:37:13+00:00

i’m trying to generate html pages by using xslt (using VS 2010 as the

  • 0

i’m trying to generate html pages by using xslt (using VS 2010 as the editor and ‘compiler/transformer’). Most of this works well and generates valid xhtml, but when trying to generate a sorted list with the help of <xsl:sort /> the order is not affected at all. I have seen it work, but when trying to determine my problem and creating the sample code below, none of my <xsl:sort /> worked.

Please, who can show me my error.

Below are my sample files.

sample.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl" ?>
<people>
    <person name="Jack" age="12">
        <adress>First road</adress>
    </person>
    <person name="Bob" age="8">
        <adress>Third road</adress>
    </person>
    <person name="Peter" age="20">
        <adress>Second road</adress>
    </person>
    <person name="Juli" age="65">
        <adress>Last road</adress>
    </person>
    <person name="Abbot" age="21">
        <adress>No road</adress>
    </person>
</people>

sample.xsl

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">

    <xsl:output
        method="xml"
        omit-xml-declaration="yes" indent="yes"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />

    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
            <head>
                <title>Sample</title>

                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            </head>

            <body>
                <h2>By @name</h2>
                <div>
                    <xsl:for-each select="people/person">
                        <xsl:sort select="@name" data-type="text" order="ascending" />
                        <xsl:value-of select="@name" />
                        <xsl:element name="br" />
                        <xsl:text />
                    </xsl:for-each>
                </div>
                <hr />
                <h2>By @age</h2>
                <div>
                    <xsl:for-each select="people/person">
                        <xsl:sort select="@age" data-type="number" order="ascending" />
                        <xsl:value-of select="@age" />
                        <xsl:element name="br" />
                        <xsl:text />
                    </xsl:for-each>
                </div>
                <hr />
                <h2>By adress</h2>
                <div>
                    <xsl:for-each select="people/person">
                        <xsl:sort select="adress" data-type="text" order="ascending" />
                        <xsl:value-of select="adress" />
                        <xsl:element name="br" />
                        <xsl:text />
                    </xsl:for-each>
                </div>
            </body>
        </html>
    </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-05-26T22:37:13+00:00Added an answer on May 26, 2026 at 10:37 pm

    You can fix this in your stylesheet by changing the stylesheet version to 1.0. In other words, change

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
    

    To

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
    

    This appears to be a bug in the .net 4 xsl transform code. See this related stackoverflow question, Problem with XSL sorting.

    What appears to happen is whenever you attempt to sort by an attribute, it actually sorts by the first child element. For example, change your XML to this and the names will sort properly:

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="Sample.xslt" ?>
    <people>
      <person name="Jack" age="12">
        <name>Jack</name>
        <adress>First road</adress>
      </person>
      <person name="Bob" age="8">
        <name>Bob</name>
        <adress>Third road</adress>
      </person>
      <person name="Peter" age="20">
        <name>Peter</Name>
        <adress>Second road</adress>
      </person>
      <person name="Juli" age="65">
        <name>Juli</Name>
        <adress>Last road</adress>
      </person>
      <person name="Abbot" age="21">
        <name>Abbot</Name>
        <adress>No road</adress>
      </person>
    </people>
    

    I found a response from Microsoft about the issue here, http://connect.microsoft.com/VisualStudio/feedback/details/620628/problem-with-xsl-sort-nodes-when-using-xslcompiledtransform, which led me to the fix I suggested above. You might try playing around with the version number for the stylesheet to see what does and does not work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.