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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:14:09+00:00 2026-06-17T18:14:09+00:00

I have faced an issue when using a variable as a condition for XPath

  • 0

I have faced an issue when using a variable as a condition for XPath evaluation. I have the following template which works fine:

<xsl:template name="typeReasonDic">
    <xsl:variable name="dic" select="$schema//xs:simpleType[@name = 'type_reason_et']"/>
    <!-- do something with the variable -->
</xsl:template>

However, when I change it to look like this:

<xsl:template name="typeReasonDic">
    <xsl:param name="choose_dic" select="@name = 'type_reason_et'"/>

    <xsl:variable name="dic" select="$schema//xs:simpleType[$choose_dic]"/>
    <!-- do something with the variable -->
</xsl:template>

it fails to find the desired node.

What I wish to get is a template with a default value for $choose_dic which can be overriden where necessary.

What am I missing here?

UPD: there is this link I found with the description of what I’m trying to do, but it doesn’t seem to work for me.

  • 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-17T18:14:11+00:00Added an answer on June 17, 2026 at 6:14 pm

    You can’t do this directly in XSLT 1.0 or 2.0 without an extension function. The problem is that with

    <xsl:template name="typeReasonDic">
        <xsl:param name="choose_dic" select="@name = 'type_reason_et'"/>
    
        <xsl:variable name="dic" select="$schema//xs:simpleType[$choose_dic]"/>
        <!-- do something with the variable -->
    </xsl:template>
    

    the <xsl:param> will evaluate its select expression a single time in the current context and store the true/false result of this evaluation in the $choose_dic variable. The <xsl:variable> will therefore select either all xs:simpleType elements under the $schema (if $choose_dic is true) or none of them (if $choose_dic) is false. This is very different from

    <xsl:variable name="dic" select="$schema//xs:simpleType[@name = 'type_reason_et']"/>
    

    which will evaluate @name = 'type_reason_et' repeatedly, in the context of each xsl:simpleType, and select those elements for which the expression evaluated to true.

    If you store the XPath expression as a string you can use an extension function such as dyn:evaluate or the XSLT 3.0 xsl:evaluate element if you’re using Saxon.

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

Sidebar

Related Questions

I faced an interesting problem today. I have 4 strings which I need to
I have done an application named irewards using Xcode 4.1 and it worked fine
Recently I faced a issue when using len() in a query to find out
While using Papyrus (+Eclipse), I faced an issue that I initially considered as an
hi i have faced an issue while accessing an object, in my program there
Today I have faced very strange behavior of sqlite3_finalize statement. I am using sqlite
Recently I've faced weird issue. I have two simple queries where one of them
I'm using NHibernate 2.2 for my database work and I've faced an issue recently.
While deploying my MVC Project, I have faced an issue of relative path w.r.t
I was writing a code using malloc for something and then faced a issue

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.