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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:58:49+00:00 2026-05-24T17:58:49+00:00

I’m trying to transform an XML document into another XML document. I’ve tried various

  • 0

I’m trying to transform an XML document into another XML document. I’ve tried various approaches, none of which produced the desired target XML document.

I have a hypothetical input XML document like this:

<rows>
 <row>
  <name>ON</name>
  <description/>
 </row>
 <row>
  <name>NY</name>
  <description/>
 </row>
</rows>

I also have two lookups:

<loc:locations>
 <loc:location>
  <loc:code>ON</loc:code>
  <loc:value>Ontario</loc:value>
 </loc:location>
 <loc:location>
  <loc:code>NY</loc:code>
  <loc:value>New York</loc:value>
 </loc:location>
</loc:locations>

<des:descriptions>
 <des:description>
  <des:code>ON</des:code>
  <des:value>Ontario is a province in Canada</des:value>
 </des:description>
 <des:description>
  <des:code>NY</des:code>
  <des:value>New York is a state in the USA</des:value>
 </des:description>
</des:descriptions>

I would like the input XML to be transformed into this target XML:

<places>
 <place>
  <name>Ontario</name>
  <description>Ontario is a province in Canada</description>
 </place>
 <place>
  <name>New York</name>
  <description>New York is a state in the USA</description>
 </place>
</places>

What is the XSLT that would accomplish this? Thanks!

  • 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-24T17:58:50+00:00Added an answer on May 24, 2026 at 5:58 pm

    Just to clean-up things for readability, because you adopted namespace convention, you can also conveniently save all lookup data into a single variable. Also use current() to access name of current node. Avoid //.

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:loc="http://sample.com/location"
        xmlns:des="http://sample.com/description"
        version="1.0">
    
        <xsl:variable name="lookup" 
            select="document('locations.xml')/loc:locations/loc:location
            | document('descriptions.xml')/des:descriptions/des:description"/>
    
        <xsl:template match="rows">
            <places>
                <xsl:apply-templates/>
            </places>
        </xsl:template>
    
        <xsl:template match="row">
            <place>
                <name>
                    <xsl:value-of select="$lookup[loc:code=current()/name]/
                        loc:value"/>
                </name>
                <description>
                    <xsl:value-of select="$lookup[des:code=current()/name]/
                        des:value"/>
                </description>
            </place>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.