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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:48:22+00:00 2026-06-17T02:48:22+00:00

I’m stuck with a small problem. The XSL-File: <?xml version=1.0 encoding=UTF-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform

  • 0

I’m stuck with a small problem.

The XSL-File:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0"  
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/xpath-functions"> 
<xsl:template match="/"> 


<xsl:variable name="unumericValue" select="10" />
<xsl:variable name="uanotherValue" select="8" />



<xsl:for-each select="/root/try">
<xsl:value-of select="var" />
<xsl:variable name="min"><xsl:value-of select="@minimum" /></xsl:variable>
<xsl:value-of select="@type" />
<xsl:variable name="referenceName"><xsl:value-of select='concat("u",var)' /></xsl:variable>
<xsl:value-of select="$referenceName" />
<xsl:if test='$referenceName > $min'>
<p>Do something.</p>
</xsl:if>
</xsl:for-each>

</xsl:template>
</xsl:stylesheet>

The XML File:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="q1.xsl"?>
<root>
<try type="compare" minimum="9">
<var>numericValue</var>
<something>...</something>
</try>

<try type="compare" minimum="10">
<var>anotherValue</var>
<something>...</something>
</try>
</root>

As you can see the XML file has two var-Elements which should match to the variables in the XSLT-File. However I don’t know which Syntax is correct.
$referenceName is just the name of the variable which I want to use. But I don’t know how to reference the name to the existing variable.

  • 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-17T02:48:24+00:00Added an answer on June 17, 2026 at 2:48 am

    $referenceName isn’t a reference to the variable with the name “unumericValue” or otherwise. It’s just the string value “unumericValue”, etc. So that will never be greater than $min. However, with a little extra work, there is a trick to find a variable by its name:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
      <xsl:variable name="numericValue" select="10" />
      <xsl:variable name="anotherValue" select="8" />
      <xsl:variable name="vars" select="document('')/*/xsl:variable" />
    
      <xsl:template match="/">
        <xsl:variable name="referenceName" select="'numericValue'" />
        <xsl:variable name="referenceValue" select="$vars[@name = $referenceName]/@select" />
        Reference value: <xsl:value-of select="$referenceValue" />
      </xsl:template>
    </xsl:stylesheet>
    

    One big limitation to note here is that this will only work for variables that are a constant numeric value.

    Here’s a way to simulate variables with constant string values:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                     xmlns:v="variables-node"
    >
      <v:variables>
        <v:variable n="numericValue" value="10" />
        <v:variable n="nonNumericValue" value="Hello World" />
      </v:variables>
      <xsl:variable name="vars" select="document('')//v:variables/v:variable" />
    
        <xsl:template match="/">
          <xsl:variable name="referenceName" select="'nonNumericValue'" />
          <xsl:variable name="referenceValue" select="$vars[@n = $referenceName]/@value" />
          <xsl:value-of select="concat('The variable with the name ', $referenceName, ' has the value ', $referenceValue)"/>
        </xsl:template>
    </xsl:stylesheet>
    

    And lastly, a way to simulate variables with calculated values:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" 
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:exslt="http://exslt.org/common"
    >
    
      <xsl:variable name="varsRaw">
        <var n="computedValue" value="{concat('2 + 4 is ', 2 + 4)}" />
        <var n="computedNumber" value="{22 div 7}" />
      </xsl:variable>
      <xsl:variable name="vars" select="exslt:node-set($varsRaw)/var" />
    
        <xsl:template match="/">
          <xsl:variable name="referenceName" select="'computedValue'" />
          <xsl:variable name="referenceValue" select="$vars[@n = $referenceName]/@value" />
          <xsl:value-of select="concat('The variable with the name ', $referenceName, ' has the value ', $referenceValue)"/>
    
          <xsl:value-of select="'     '"/>
    
          <xsl:variable name="referenceName2" select="'computedNumber'" />
          <xsl:variable name="referenceValue2" select="$vars[@n = $referenceName2]/@value" />
          <xsl:value-of select="concat('The variable with the name ', $referenceName2, ' has the value ', $referenceValue2)"/>
        </xsl:template>
    </xsl:stylesheet>
    

    The last approach is probably actually the most orthodox, but requires the XSLT processor-dependent (at least in XSLT 1.0) node-set() function.

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

Sidebar

Related Questions

I'm parsing an XML file, the creators of it stuck in a bunch social
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have been unable to fix a problem with Java Unicode and encoding. The
I'm using an ASP request returning a XML file containing some latin characters. By
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.