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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:44:29+00:00 2026-06-02T19:44:29+00:00

Assume I have variables $a , $b , $c and $d which all hold

  • 0

Assume I have variables $a, $b, $c and $d which all hold numbers. I would like to get the smallest (largest) value. My typical XSLT 1.0 approach to this is

<xsl:variable name="minimum">
  <xsl:for-each select="$a | $b | $c | $d">
    <xsl:sort
      select="."
      data-type="number"
      order="ascending" />
    <xsl:if test="position()=1"><xsl:value-of select="." /></xsl:if>
  </xsl:for-each>
</xsl:variable>

However, my xslt 1.0 processor complains with

runtime error: file stylesheet.xslt line 106 element for-each
The ‘select’ expression does not evaluate to a node set.

How can I compute the minimum (maximum) of the given values?


Of course, I could use a long series of <xsl:when> statements and check all combinations, but I’d rather like a smaller solution.

  • 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-02T19:44:30+00:00Added an answer on June 2, 2026 at 7:44 pm

    If the variables have statically defined values (not dynamically computed), then something like the following can be done with XSLT 1.0:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text"/>
    
     <xsl:variable name="vA" select="3"/>
     <xsl:variable name="vB" select="1"/>
     <xsl:variable name="vC" select="9"/>
     <xsl:variable name="vD" select="5"/>
    
     <xsl:template match="/">
         <xsl:for-each select=
          "document('')/*/xsl:variable
             [contains('|vA|vB|vC|vD|', concat('|', @name, '|'))]
               /@select
          ">
          <xsl:sort data-type="number" order="ascending"/>
    
          <xsl:if test="position() = 1">
           Smallest: <xsl:value-of select="."/>
          </xsl:if>
          <xsl:if test="position() = last()">
           Largest: <xsl:value-of select="."/>
          </xsl:if>
         </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on any XML document (not used), the wanted, correct result is produced:

       Smallest: 1
       Largest: 9
    

    II. Now, suppose the variables are dynamically defined.

    We can do something like this (but need the xxx:node-set() extension function):

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:ext="http://exslt.org/common">
     <xsl:output method="text"/>
    
     <xsl:variable name="vA" select="number(/*/*[3])"/>
     <xsl:variable name="vB" select="number(/*/*[1])"/>
     <xsl:variable name="vC" select="number(/*/*[9])"/>
     <xsl:variable name="vD" select="number(/*/*[5])"/>
    
     <xsl:template match="/">
         <xsl:variable name="vrtfStore">
           <num><xsl:value-of select="$vA"/></num>
           <num><xsl:value-of select="$vB"/></num>
           <num><xsl:value-of select="$vC"/></num>
           <num><xsl:value-of select="$vD"/></num>
         </xsl:variable>
    
         <xsl:for-each select="ext:node-set($vrtfStore)/*">
          <xsl:sort data-type="number" order="ascending"/>
    
          <xsl:if test="position() = 1">
           Smallest: <xsl:value-of select="."/>
          </xsl:if>
          <xsl:if test="position() = last()">
           Largest: <xsl:value-of select="."/>
          </xsl:if>
         </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on the following XML document:

    <nums>
      <num>01</num>
      <num>02</num>
      <num>03</num>
      <num>04</num>
      <num>05</num>
      <num>06</num>
      <num>07</num>
      <num>08</num>
      <num>09</num>
      <num>10</num>
    </nums>
    

    the wanted, correct result is produced:

       Smallest: 1
       Largest: 9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have the following input in Pig: some And I would like to
Assume all the variables have been declared previously... because they have been. The child
Assume I have a Class Foo which has many internal variables, only one constructor
Assume I have a C# class like this: [XmlRoot(floors)] public class FloorCollection { [XmlElement(floor)]
Assume you have a file which has been committed in your Git repo. You
Assume I have this domain object... public class SpansMultipleTables { public int CommonID {get;
Say you have several large arrays of variables (which generally are strings), and you
Assume I have the following string: Hellotoevryone<img height=115 width=150 alt= src=/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg />Iamsogladtoseeall. This
Assume I have access to a SMB server at IP 1.2.3.4, how can I
Assume I have a application that stores data,gets data and processes data and stores

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.