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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:35:07+00:00 2026-05-19T12:35:07+00:00

I think this is a beginner question, it is regarding the variable references across

  • 0

I think this is a beginner question, it is regarding the variable references across different XSLT templates. The structure is like this:

I firstly have an XSLT file, and in it, I’ve declared an template A, and within it, I basically loop through each record(row) of an XML file, say, xml_A, and I’ve declared a variable to refer to a particular field called “id” of the current record in xml_A. Then, within this for-each loop, I need to call another template B.

 <xsl:template name="A">
 <LoopA> 
    <xsl:for-each select="$xml_A//xml_A_row">
    <xsl:variable name="id_A" select="id"/>
     ....
 </LoopA>
 <xsl:call-template name="B"/> 
 </xsl:template> 

For template B, I actually created another XSLT file under the same directory. The B contains millions of records from xml file “xml_B”, but I only want the records that have the SAME id field as the current record of template A. Here is how I did it:

<xsl:template name="B">
<LoopB>
<xsl:variable name="id_A" select="id"/>
 ...
</loopB>
</xsl:template>    

Here comes my question. I used the above <xsl:variable name="id_A" select="id"/> to refer to the id field of the current record that the upper loop is on. However, I am not sure whether this is correct, I’ve done some testing, since the data file is so huge, thus it is not easy to visually test if this is doing the right thing.

So I wonder if anybody could advise if the above reference to variable of the outer-loop is correct since if I delete that, the XML editor will complain.

Thanks in advance.

Update from comments

I think I didn’t make it clear enough.
Actually neither xml_A or xml_B is the
xml files that are going to be XSLTed.
They are just data files which I will
use to pull data from, and there’s
another XML file C that is used as for
applying the stylesheet on and it is
empty. So in my style sheet, using
the provide answer, I must have a way to
make it refer to this data storage
file xml_A.

  • 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-05-19T12:35:08+00:00Added an answer on May 19, 2026 at 12:35 pm

    The typical XSLT style would be:

    <xsl:variable name="xml_B" select="document('xml_B.xml')">
    
    <xsl:template match="xml_A_row">
       <xsl:apply-templates select="$xml_B/path/to/xml_B_row[id = current()/id]"/>
    </xsl:template>
    

    Note: Pattern matching instead of xsl:for-each and named templates, xsl:apply-templates instead of xsl:call-template, current() function to reference context node.

    EDIT: In order to look more like your incomplete stylesheet fragment…

    <xsl:key name="kBRowById" match="xml_B_row" use="id"/>
    
    <xsl:variable name="xml_A" select="document('xml_A.xml')"/>
    <xsl:variable name="xml_B" select="document('xml_B.xml')"/>
    
    <xsl:template name="A">
      <LoopA>
          <xsl:for-each select="$xml_B">
              <xsl:apply-templates select="key('kBRowById',$xml_A//xml_A_row/id)"
                                   mode="just-in-case"/>
          </xsl:for-each>
      </LoopA>
    </xsl:template>
    
    <xsl:template match="xml_B_row" mode="just-in-case">
      <LoopB/>
    </xsl:template>
    

    Note: Using xsl:key because you wrote “millons of records”, xsl:for-each with singleton root node in order to change context node for fn:key() function, using outer most scope variable $xml_A for cross reference key value. The mode is there just in case there is conflic with other rules of the stylesheet you didn’t provide.

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

Sidebar

Related Questions

Absolute beginner question: I have a template file index.html that looks like this: ...
I think this is a multi-part question, so bear with me. Currently all of
I think this must be simple but I can't get it right... I have
I think this mostly applies to web applications, since you often see things like
I think this is pretty typical, you have the same website project with an
I think this must be a stupid question, but why do the results of
I think this question is rather easy for you shell scripting monsters. I am
I'm following a tutorial. (Real World Haskell) And I have one beginner question about
hello i'm a beginner java developer and this is one question in a list
I think this is specific to IE 6.0 but... In JavaScript I add a

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.