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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:37:07+00:00 2026-06-14T11:37:07+00:00

I have following question relating to XPATH1 and XPATH2: <document> <val>3</val> <val>11</val> <val>3</val> <val>2</val>

  • 0

I have following question relating to XPATH1 and XPATH2:

<document>
    <val>3</val>
    <val>11</val>
    <val>3</val>
    <val>2</val>
    <val>12</val>
    <val>5</val>
    <val>0</val>
    <val>7</val>
</document>

xpath1: max

//val[not(. < //val)]

min:

//val[not(. > //val)]

xpath2:

document/val[. = max(//val)]

document/val[. = min(//val)]

Why don’t I get the same result in XPATH2 processing with the xpath1-max query:

//val[not(. < //val)]

It seems that I get the LAST node (with val 7), but not the highest value … the other way around for MIN value works fine with XPATH2 processing:

//val[not(. > //val)]

Can someone help me out there ?

  • 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-14T11:37:09+00:00Added an answer on June 14, 2026 at 11:37 am

    Very good point.

    In xpath 1 (and xslt 1.0), //val[not(. < //val)] is inherently casting the text values to numbers, and doing the comparison on numbers.

    Hence, you get the correct min and max values.

    However, in xpath 2 (and xslt 2.0), the text isn’t cast to numeric, and instead, a string comparison is done. So using string comparison, ‘7’ is > ’12’ and hence 7 will still be the highest value (it isn’t returning just the last value in the list – try swapping the order of values around)

    So what you should do to be safe in both xslt 1 and 2 is to use the number() function to do the cast on the text, to ensure that a numeric comparison is done.

    Max:

    //val[not(number(.) &lt; //val)]
    

    Min:

    //val[not(number(.) &gt; //val)]
    

    Using Saxon with the stylesheet:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:output method="xml" indent="yes"/>
    
        <xsl:template match="/">
            <x>
                <Max1>
                    <xsl:value-of select="//val[not(number(.) &lt; //val)]" />
                </Max1>
                <Min1>
                    <xsl:value-of select="//val[not(number(.) &gt; //val)]" />
                </Min1>
                <Max2>
                    <xsl:value-of select="/document/val[. = max(//val/text())]" />
                </Max2>
                <Min2>
                    <xsl:value-of select="/document/val[. = min(//val/text())]" />
                </Min2>
            </x>
        </xsl:template>
    </xsl:stylesheet>
    

    Returns

    <x>
       <Max1>12</Max1>
       <Min1>0</Min1>
       <Max2>12</Max2>
       <Min2>0</Min2>
    </x>
    

    as expected.

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

Sidebar

Related Questions

Question relating to optim function in R I have the following code so far
I have the following question: Why do I get nothing when I do appointment.GetType().GetProperties()
I have following question: How can I scan a complete image to get for
Possible Duplicate: read iphone sms messages? I have following question related to get sms.
I have following question on adobe omniture How we can register an iPhone app
I am new to Spring Batch. I have following question. I am using Spring
I have the following question. I have a set of Fortran90 source files, most
I have the following question, and it screams at me for a solution with
I have the following question. How can I print an output file line by
I have the following question about JPA: Can I save the order of the

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.