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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:40:21+00:00 2026-05-20T13:40:21+00:00

Use XSL to build a unique map from child nodes, then display it in

  • 0

Use XSL to build a unique map from child nodes, then display it in a table

I would like to create a xsl that takes the following xml documents as input

Source.xml

<root>
<children>
<child>
Source-A
</child>
<child>
Source-B
</child>
</children>
</root>

Source-A.xml

<child>
 <Objects>
  <Object>
   <Key>Key-1234</Key>
  </Object>
  <Object>
   <Key>Key-5678</Key>
  </Object>
 </Objects>
</child>

Source-B.xml

<child>
 <Objects>
  <Object>
   <Key>Key-5678</Key>
  </Object>
  <Object>
   <Key>Key-ABCD</Key>
  </Object>
 </Objects>
</child>

and creates some html output that looks like this.

<table border=1>
 <tr>
  <td>
   Key
  </td>
  <td>
   Key-1234
  </td>
  <tr>
  </tr>
  <td colspan="2">
   Source-A
  </td>
 </tr>

 <tr>
  <td>
   Key
  </td>
  <td>
   Key-5678
  </td>
  <tr>
  </tr>
  <td colspan="2">
   Source-A
   Source-B
  </td>
 </tr>

 <tr>
  <td>
   Key
  </td>
  <td>
   Key-ABCD
  </td>
  <tr>
  </tr>
  <td colspan="2">
   Source-B
  </td>
 </tr>

</table>

Here is what I have so far, but I’m not sure it’s even possible, any hints on how to do it? Or am I trying to do something thats not possible?

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <xsl:template match="/">
    <html>
      <!--<xsl:variable name="keyMap" />-->
      <xsl:variable name="keyMap">
        <xsl:for-each select="root/children/child">
          <xsl:variable name="object" select="."/>
          <!--<xsl:value-of select="$object"/>-->
          <xsl:for-each select="document(concat(translate($object,'&#10;',''),'.xml'))/child/Objects/Object">
             <xsl:value-of select="Key"/>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:variable>
      <xsl:value-of select="$keyMap"/>

    </html>
  </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-20T13:40:22+00:00Added an answer on May 20, 2026 at 1:40 pm

    Update: Two phase transformation with node-set() extension function.

    This stylesheet:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:msxsl="urn:schemas-microsoft-com:xslt"
     exclude-result-prefixes="msxsl">
        <xsl:key name="kKeyByValue" match="Key" use="."/>
        <xsl:template match="/">
            <xsl:variable name="vFirstPass">
                <xsl:for-each select="root/children/child">
                    <xsl:variable name="vSource" select="normalize-space()"/>
                    <source href="{$vSource}">
                        <xsl:copy-of select="document(concat($vSource,'.xml'))
                                                /child/Objects/Object/Key"/>
                    </source>
                </xsl:for-each>
            </xsl:variable>
            <table border="1">
                <xsl:apply-templates select="msxsl:node-set($vFirstPass)/*"/>
            </table>
        </xsl:template>
        <xsl:template match="text()"/>
        <xsl:template match="Key[count(.|key('kKeyByValue',.)[1]) = 1]">
            <tr>
                <td>Key</td>
                <td>
                    <xsl:value-of select="."/>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <xsl:for-each select="key('kKeyByValue',.)">
                        <xsl:value-of select="normalize-space(../@href)"/>
                        <xsl:if test="position()!=last()">
                            <xsl:text>&#x20;</xsl:text>
                        </xsl:if>
                    </xsl:for-each>
                </td>
            </tr>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <table border="1">
        <tr>
            <td>Key</td>
            <td>Key-1234</td>
        </tr>
        <tr>
            <td colspan="2">Source-A</td>
        </tr>
        <tr>
            <td>Key</td>
            <td>Key-5678</td>
        </tr>
        <tr>
            <td colspan="2">Source-A Source-B</td>
        </tr> 
        <tr>
            <td>Key</td>
            <td>Key-ABCD</td>
        </tr>
        <tr>
            <td colspan="2">Source-B</td>
        </tr>
    </table>
    

    Without extensions, this stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kChildByDocument"
                 match="child"
                 use="generate-id(
                         document(concat(normalize-space(),'.xml'),.)
                      )"/>
        <xsl:key name="kRootByKeys"
                 match="/"
                 use="child/Objects/Object/Key"/>
        <xsl:variable name="vSource" select="/"/>
        <xsl:template match="/" name="getDocuments">
            <xsl:param name="pDocuments" select="/.."/>
            <xsl:param name="pURIs" select="root/children/child"/>
            <xsl:choose>
                <xsl:when test="$pURIs">
                    <xsl:call-template name="getDocuments">
                        <xsl:with-param name="pDocuments"
                         select="$pDocuments |
                                 document(concat(normalize-space($pURIs[1]),
                                                 '.xml'),
                                          .)"/>
                        <xsl:with-param name="pURIs"
                                        select="$pURIs[position()>1]"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <table border="1">
                        <xsl:call-template name="makeRows">
                            <xsl:with-param name="pDocuments"
                                            select="$pDocuments"/>
                        </xsl:call-template>
                    </table>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <xsl:template name="makeRows">
            <xsl:param name="pDocuments" select="/.."/>
            <xsl:param name="pKeys"
                       select="$pDocuments/child/Objects/Object/Key"/>
            <xsl:if test="$pKeys">
                <xsl:variable name="vKey" select="$pKeys[1]"/>
                <tr>
                    <td>Key</td>
                    <td>
                        <xsl:value-of select="$vKey"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <xsl:for-each select="$pDocuments[
                                                 key('kRootByKeys',$vKey)
                                              ]">
                            <xsl:variable name="vDocument"
                                          select="generate-id()"/>
                            <xsl:for-each select="$vSource">
                                <xsl:value-of
                                     select="normalize-space(
                                                key('kChildByDocument',
                                                    $vDocument)
                                             )"/>
                            </xsl:for-each>
                            <xsl:if test="position()!=last()">
                                <xsl:text>&#x20;</xsl:text>
                            </xsl:if>
                        </xsl:for-each>
                    </td>
                </tr>
                <xsl:call-template name="makeRows">
                    <xsl:with-param name="pDocuments" select="$pDocuments"/>
                    <xsl:with-param name="pKeys" select="$pKeys[.!=$vKey]"/>
                </xsl:call-template>
            </xsl:if>
        </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 could use some help creating an XSL template that will take a string
I have a xsl file where i need to use parameters from an external
I have two nested loop in XSL like this, at this moment I use
How to use xsl:for-each in xslt to get value iteratively from an xml file
how to use xsl to change name of child node if it = to
What I am trying to do is use XSL to output all unique element
I needed to use XSL to generate simple plain text output from XML. Since
I have made use of xsl:when to display my details. The details which I
I'm trying to use a .xsl file so that it will return a HTML
I would like to know how to store a value from XML to an

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.