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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:46:13+00:00 2026-05-11T21:46:13+00:00

I have searched around and found some tutorials for xsl:key and key() function, but

  • 0

I have searched around and found some tutorials for xsl:key and key() function, but somehow I still am missing some understanding apparently.

There is a XML-XML transformation I need to do, which includes some 10 fields where you I have to take string values from source XML, find appropriate numeric codes from appropriate lookup tables (provided), and put those codes in resulting XML.

I have a working version of this doing xsl:for-each for lookup table, but I suspect it is suboptimal and would like to know if I should have used select=”key(‘CR-Lookup’,$CR)” instead somhow.

So, what I want to do is (deep part of tree):

<Contributor>
<ContributorRole>producer</ContributorRole>
<ContributorName>Anglet, J.</ContributorName>
</Contributor>

to be transformed into something like this:

<Contributor>
<ContributorRole id="7" code="818"/>
<Value id="Name">Anglet, J.</Value>
</Contributor>

The files I’ve made like thus:

Lookup table file lookup_ContributorRole.xml :

<lookup id="ContributorRole">
<row>
  <id>7</id>
  <parentid>NULL</parentid>
  <valueMember>1</valueMember>
  <displayMember>producer</displayMember>
  <code>818</code>
  <externalId>NULL</externalId>
  <description>NULL</description>
</row>
<!-- more <row>s...-->
</lookup>

Amd the XSLT file, where I attempt to do the matching:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
    xmlns:foxml="info:fedora/fedora-system:def/foxml#" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:rel="info:fedora/fedora-system:def/relations-external#"
    xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema" 
    xmlns:audit="info:fedora/fedora-system:def/audit#" 
    xmlns:fedoraxsi="http://www.w3.org/2001/XMLSchema-instance"

    exclude-result-prefixes="xsl foxml rdf rel oai_dc dc xsi audit fedoraxsi"
>
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml" />

<xsl:key name="CR-lookup" match="row" use="displayMember"/>
<xsl:variable name="CRTable" select="document('lookup_ContributorRole.xml')/lookup/row"/>

<xsl:template match="Contributor">
    <Contributor>
    <xsl:variable name="CR"><xsl:value-of select="ContributorRole"/></xsl:variable>
    <ContributorRole>
    <xsl:for-each select="$CRTable">
        <xsl:if test="displayMember=$CR">
            <xsl:attribute name="id"><xsl:value-of select="id"/></xsl:attribute>
            <xsl:attribute name="code"><xsl:value-of select="code"/></xsl:attribute>
        </xsl:if>
    </xsl:for-each>
    </ContributorRole>
    <Value id="Name"><xsl:value-of select="ContributorName"/></Value>
    </Contributor>
</xsl:template>

    <xsl:template match="/">
    <DigitalObject>
        <Core>
            <xsl:for-each select="/foxml:digitalObject/foxml:datastream[@ID='DigitalObjectLL']/foxml:datastreamVersion">
             <xsl:sort select="@CREATED" order="descending"/>
             <xsl:if test="position() = 1">
                <xsl:for-each select="./foxml:xmlContent/lnbdo">
                    <xsl:apply-templates select="Contributor"/>
                </xsl:for-each>
             </xsl:if>
           </xsl:for-each>
        </Core>
    </DigitalObject>
    </xsl:template>
</xsl:stylesheet>
  • 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-11T21:46:13+00:00Added an answer on May 11, 2026 at 9:46 pm

    You have switch the context document before you can use the key:

    <xsl:variable name="CRTable" select="document('lookup_ContributorRole.xml')"/>
    
    <xsl:template match="Contributor">
      <Contributor>
        <xsl:variable name="CR" select="ContributorRole"/>
        <ContributorRole>
          <xsl:for-each select="$CRTable"><!-- change context document -->
            <xsl:for-each select="key('CR-lookup', $CR)">
              <xsl:attribute name="id"><xsl:value-of select="id"/></xsl:attribute>
              <xsl:attribute name="code"><xsl:value-of select="code"/></xsl:attribute>
              ...
    

    With XSLT 2.0 you could do

    <xsl:for-each select="key('CR-lookup', $CR, $CRTable)">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the strval() function to convert a number… May 12, 2026 at 12:07 am
  • Editorial Team
    Editorial Team added an answer create function xcurr return varchar2 is v_curr varchar2(32); begin SELECT… May 12, 2026 at 12:07 am
  • Editorial Team
    Editorial Team added an answer Define "change in the contents of a folder". If it… May 12, 2026 at 12:07 am

Related Questions

I want to get smarter in AJAX, but not sure which way to go.
I would like to add graphing to my User Controls in ASP.NET MVC. I
My automatic test-framework tests a bunch of Excel sheets required by our customers with
I have configured java to dump garbage collection information into the logs ( verbose

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.