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

  • SEARCH
  • Home
  • 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 7794619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:49:38+00:00 2026-06-01T22:49:38+00:00

I have a set of elements with different attributes, like this: <?xml version=1.0 encoding=utf-8?>

  • 0

I have a set of elements with different attributes, like this:

<?xml version="1.0" encoding=utf-8"?>
<root>
  <elem at="4" iterate="third" />
  <foo/>
  <elem at="1" iterate="first" />
  <bar/>
  <elem start="3" end="9" iterate="second" />
</root>

I want to iterate over the elem tags, so I specified the for-each like this:

<xsl:for-each select="/root/elem">

so far so good, but now I want to sort these elements, according to their @at and @start field, while each elem is guaranteed to have either @at or @start. I annotated in the @iterate attribute how I want the tags to be iterated over (just for the sake of clarity here).

My approach was this

<xsl:sort select="@at or @start" data-type="number" order="ascending" />

But that doesn’t seem to work as intended as elements with an @at attribute seem to be prioritised over elements with an @start attribute.

So, how can I tell XSLT (1.0) not to distinguish between the name of the attribute that is set and simply sort according to its respective value?

  • 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-01T22:49:40+00:00Added an answer on June 1, 2026 at 10:49 pm

    You are not far off. Try using the union operator |

    <xsl:sort select="@at|@start" data-type="number" order="ascending" />
    

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="root">
          <root>
             <xsl:apply-templates select="elem">
                <xsl:sort select="@at|@start" data-type="number" order="ascending" />
             </xsl:apply-templates>
          </root>
       </xsl:template>
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your XML, the following is output

    <root>
       <elem at="1" iterate="first"></elem>
       <elem start="3" end="9" iterate="second"></elem>
       <elem at="4" iterate="third"></elem>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set of 6 elements and I would like to filter by every
To set the name of an XML element I use annotations like this: @XmlElement(name
I have an XDocument like this one set as a DataContext of my Window
Assuming an XML like this: <my:Root xmlns:my=http://foo/bar> <my:FieldBasic>content</my:FieldBasic> <my:FieldComplex> <html xml:space=preserve xmlns=http://www.w3.org/1999/xhtml> <div><h1>content</h1></div> </html>
I have a set of pages acting as a slideshow where different elements are
I have a set of unique elements (there are not two identical elements). And
I have a set of selected elements in jQuery: <div class=element></div> <div class=element></div> <div
I have a set of vertically ordered elements. They are displayed with the following
I have a vector of booleans. I need to set its elements from n-th
I have a simple website with a master-page. To set properties to elements on

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.