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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:40:32+00:00 2026-06-17T16:40:32+00:00

Relating to this question, is it possible to use variables inside xsl:key? I want

  • 0

Relating to this question, is it possible to use variables inside xsl:key? I want to do smth like this:

<xsl:key name="ChargesKey" match="$ChargesForDisplay/charge" use="Name"/>

I’m using XSLT 1.0 with ASP.Net

  • 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-17T16:40:33+00:00Added an answer on June 17, 2026 at 4:40 pm

    I believe I can safely assume that you are referring to dynamically-generated node-set variables (as opposed to those selected from the source DOM, which are trivial), and yes it is possible to perform a key-match on the contents of a dynamically generated node-set variable (as I demonstrate for this question).

    Assuming you have a variable like this:

    <xsl:variable name="ChargesForDisplay">
    <charge>
       <Name>Name1</Name>
    </charge>
    <charge>
       <Name>Name2</Name>
    </charge>
    <charge>
       <Name>Name1</Name>
    </charge>
    <charge>
       <Name>Name3</Name>
    </charge>
    </xsl:variable>
    

    You would define the key like this:

    <xsl:key name="ChargesKey" match="charge" use="Name"/>
    

    And then you can apply it like this:

      <xsl:template match="/">
          <xsl:apply-templates select="msxsl:node-set($ChargesForDisplay)" />
      </xsl:template>
    
      <xsl:template
       match="charge[generate-id(.)=generate-id(key('ChargesKey',Name)[1])]">
        <xsl:variable name="matchingItems" select="key('ChargesKey', Name)" />
        ...
      </xsl:template>
    

    Of course, if the variable contains a selection of nodes from the source XML DOM, then it’s just the same approach, except you don’t need to use msxsl:node-set().

    I suspect that having a key on a node-name that’s also present in the source XML document or multiple dynamically-generated node-set variables may cause grouping to produce unexpected results(because the key() function would locate nodes from both the variable and the source document). For this reason, I’d suggest defining keys on nodes that would only be present in one particular variable and nowhere else.

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

Sidebar

Related Questions

I have this question relating to Lucene. I have a form and I get
Relating to this question i was wondering if .NET has any libs (or a
This question is relating to a specific functionality that a client has requested for
This question is relating to 2 php scripts. The first script is called pick_modcontact.php
I am struggling with a WCF issue relating to name resolution-or something like so.
This is relating to my last question mysql query with AND, OR and NOT
I've read around and found this answered question about a problem relating to this
two relating question: I have a table that is in use in a production
I am re-asking this as my previous question was mistakenly closed. Is it possible
This may seem like a silly question. I am running a neural network through

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.