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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:49:34+00:00 2026-05-30T01:49:34+00:00

Answering another XSLT question on this site, I stumbled on a difference between XSLT

  • 0

Answering another XSLT question on this site, I stumbled on a difference between XSLT 1.0 and 2.0 that I don’t understand. Who can explain what is happening here, and how the difference may be resolved?
Note: I am using XML Spy version 2011 sp1 (x64).

My input XML is

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <Manager grade="10" id="26">
        <Employee id="1" grade="9"/>
        <Employee id="2" grade="8"/>
    </Manager>
    <Manager grade="10" id="27">
        <Employee id="3" grade="9"/>
        <Employee id="4" grade="8"/>
        <Employee id="5" grade="4"/>
    </Manager>
    <Manager grade="7" id="28">
        <Employee id="6" grade="8"/>
        <Employee id="7" grade="7"/>
        <Employee id="8" grade="6"/>
        <Employee id="9" grade="9"/>
    </Manager>
    <Manager grade="9" id="29">
        <Employee id="10" grade="9"/>
        <Employee id="11" grade="8"/>
        <Employee id="12" grade="7"/>
    </Manager>
</root>

I wish to select the set of Employees that have a grade larger than or equal to the managers grade. For this I wrote the following 1.0 transformation:

<?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" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
        <root>
            <xsl:apply-templates select="root/Manager"/>
        </root>
    </xsl:template>

    <xsl:template match="Manager">
        <mgr>
            <managerId><xsl:value-of select="@id"/></managerId>
            <managerGrade><xsl:value-of select="@grade"/></managerGrade>
            <empsSelection>
                <xsl:copy-of select="Employee[@grade &gt;= ../@grade]"/>
            </empsSelection>
        </mgr>
    </xsl:template>
</xsl:stylesheet>

The output is the expected

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <mgr>
        <managerId>26</managerId>
        <managerGrade>10</managerGrade>
        <empsSelection/>
    </mgr>
    <mgr>
        <managerId>27</managerId>
        <managerGrade>10</managerGrade>
        <empsSelection/>
    </mgr>
    <mgr>
        <managerId>28</managerId>
        <managerGrade>7</managerGrade>
        <empsSelection>
            <Employee id="6" grade="8"/>
            <Employee id="7" grade="7"/>
            <Employee id="9" grade="9"/>
        </empsSelection>
    </mgr>
    <mgr>
        <managerId>29</managerId>
        <managerGrade>9</managerGrade>
        <empsSelection>
            <Employee id="10" grade="9"/>
        </empsSelection>
    </mgr>
</root>

But when I change the XSLT version to 2.0 (take above stylesheet and change stylesheet/@version to 2.0), I get the below different and unexpected result:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <mgr>
        <managerId>26</managerId>
        <managerGrade>10</managerGrade>
        <empsSelection>
            <Employee id="1" grade="9"/>
            <Employee id="2" grade="8"/>
        </empsSelection>
    </mgr>
    <mgr>
        <managerId>27</managerId>
        <managerGrade>10</managerGrade>
        <empsSelection>
            <Employee id="3" grade="9"/>
            <Employee id="4" grade="8"/>
            <Employee id="5" grade="4"/>
        </empsSelection>
    </mgr>
    <mgr>
        <managerId>28</managerId>
        <managerGrade>7</managerGrade>
        <empsSelection>
            <Employee id="6" grade="8"/>
            <Employee id="7" grade="7"/>
            <Employee id="9" grade="9"/>
        </empsSelection>
    </mgr>
    <mgr>
        <managerId>29</managerId>
        <managerGrade>9</managerGrade>
        <empsSelection>
            <Employee id="10" grade="9"/>
        </empsSelection>
    </mgr>
</root>

Why is this and how should the stylesheet be changed in order to get the correct result in both XSLT 1.0 and 2.0 version?

  • 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-30T01:49:36+00:00Added an answer on May 30, 2026 at 1:49 am

    I think with XSLT 2.0 you by default get comparison as strings while with XSLT 1.0 the comparison operator converts any operands to numbers first which are then compared so with XSLT 2.0 you need

    <xsl:template match="Manager">
        <mgr>
            <managerId><xsl:value-of select="@id"/></managerId>
            <managerGrade><xsl:value-of select="@grade"/></managerGrade>
            <empsSelection>
                <xsl:copy-of select="Employee[number(@grade) &gt;= number(current()/@grade)]"/>
            </empsSelection>
        </mgr>
    </xsl:template>
    

    to get the result you want. Of course using other number types like xs:integer(@grade) should do as well.

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

Sidebar

Related Questions

So, in answering another question on this site, I wrote a class for someone
In answering another persons question here on SO, I discovered that there is a
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
This question arose when I was working on answering another question about best practices
As part of answering another question, I wanted to show that the insane level
While answering another question I bumped into this interesting situation Where WCF is happy
I ran into this question when i was answering another guys question. How do
When answering another question I started to wonder how I could Add new properties
In answering this question ( https://stackoverflow.com/questions/352317/c-coding-question#352327 ), it got me wondering... Is there any
In answering this code golf question , I ran across a problem in my

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.