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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:08:27+00:00 2026-06-18T14:08:27+00:00

I’m using xsl for a XML transformation and I have to use multiple lookups

  • 0

I’m using xsl for a XML transformation and I have to use multiple lookups for that. Lookup xml’s have following format.

<lookups>
    <lookup attr1="val1a" attr2="val1b">
    <lookup attr1="val2a" attr2="val2b">
<lookups>

All lookup xmls use above format. for example lookup file for element A is there and another lookup file for element B is also there with same element structure but different values which are relevant to element B. Then I’m doing my lookups in main xsl file as follows.

<!-- here come the first lookup for element A -->
<xsl:key name="A-lookup" match="lookup" use="@attr1"/>
<xsl:variable name="ALookupDoc" select="document('ALookup.xml')"/>

<xsl:template match="A">
    <Anew>
        <xsl:apply-templates select="$ALookupDoc/*">
        <xsl:with-param name="curr-code" select="string(.)"/>
    </xsl:apply-templates>
    </Anew>
</xsl:template>

<xsl:template match="lookups">
    <xsl:param name="curr-code"/>
    <xsl:value-of select="key('A-lookup', $curr-code)/@attr2"/>
</xsl:template>

<!-- And the second one for element B -->
<xsl:key name="B-lookup" match="lookup" use="@attr1"/>
<xsl:variable name="BLookupDoc" select="document('BLookup.xml')"/>

<xsl:template match="B">
    <Anew>
        <xsl:apply-templates select="$BLookupDoc/*">
        <xsl:with-param name="curr-code" select="string(.)"/>
    </xsl:apply-templates>
    </Anew>
</xsl:template>

<xsl:template match="lookups">
    <xsl:param name="curr-code"/>
    <xsl:value-of select="key('B-lookup', $curr-code)/@attr2"/>
</xsl:template>

OK now. the problem is first lookup which is for the element A works fine. But not the second one. As I see there are two problematic parts.

  1. Both lookups have same element names(lookups and lookup). Once I change second lookup XML to differnt elements(lookupsX and lookupX) and templates accordingly they work fine.
  2. There are two templates for same element(lookups for element A and B)

Still I’m not sure exactly where the problem is.

  • 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-18T14:08:28+00:00Added an answer on June 18, 2026 at 2:08 pm

    I think the problem is that you have two templates with exactly the same match value, so only one of them is actually being used. You could resolve this by giving them different modes, but how about something like this:

      <!-- here come the first lookup for element A -->
      <xsl:key name="A-lookup" match="lookup" use="@attr1"/>
      <xsl:variable name="ALookupDoc" select="document('ALookup.xml')"/>
    
      <xsl:template match="A">
        <Anew>
          <xsl:apply-templates select="$ALookupDoc/*">
            <xsl:with-param name="curr-code" select="string(.)"/>
            <xsl:with-param name="keyName" select="'A-lookup'" />
          </xsl:apply-templates>
        </Anew>
      </xsl:template>
    
      <!-- And the second one for element B -->
      <xsl:key name="B-lookup" match="lookup" use="@attr1"/>
      <xsl:variable name="BLookupDoc" select="document('BLookup.xml')"/>
    
      <xsl:template match="B">
        <Anew>
          <xsl:apply-templates select="$BLookupDoc/*">
            <xsl:with-param name="curr-code" select="string(.)"/>
            <xsl:with-param name="keyName" select="'B-lookup'" />
          </xsl:apply-templates>
        </Anew>
      </xsl:template>
    
      <xsl:template match="lookups">
        <xsl:param name="curr-code"/>
        <xsl:param name="keyName" />
    
        <xsl:value-of select="key($keyName, $curr-code)/@attr2"/>
      </xsl:template>
    

    Then again, you might not need two keys, since they both have the same definition. Please see if this works:

      <!-- here come the first lookup for element A -->
      <xsl:key name="lookup" match="lookup" use="@attr1"/>
      <xsl:variable name="ALookupDoc" select="document('ALookup.xml')"/>
    
      <xsl:template match="A">
        <Anew>
          <xsl:apply-templates select="$ALookupDoc/*">
            <xsl:with-param name="curr-code" select="string(.)"/>
          </xsl:apply-templates>
        </Anew>
      </xsl:template>
    
      <!-- And the second one for element B -->
      <xsl:variable name="BLookupDoc" select="document('BLookup.xml')"/>
    
      <xsl:template match="B">
        <Anew>
          <xsl:apply-templates select="$BLookupDoc/*">
            <xsl:with-param name="curr-code" select="string(.)"/>
          </xsl:apply-templates>
        </Anew>
      </xsl:template>
    
      <xsl:template match="lookups">
        <xsl:param name="curr-code"/>
    
        <xsl:value-of select="key('lookup', $curr-code)/@attr2"/>
      </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm using an ASP request returning a XML file containing some latin characters. By
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.