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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:58:21+00:00 2026-05-19T01:58:21+00:00

I have a input file Main.xml <?xml version=1.0 encoding=utf-8 ?> <Employees> <Employee> <id name=id>1</id>

  • 0

I have a input file

Main.xml

<?xml version="1.0" encoding="utf-8" ?>
<Employees>
<Employee>
<id name="id">1</id>
<firstname >ABC</firstname>
<lastname >XYZ</lastname>
<age >32</age>
</Employee>
</Employees>

and 2 Lookup files:

Lookup1.xml

 <?xml version="1.0" encoding="utf-8"?>
  <Employees>
  <Employee id="1">
   <department code="102">HR</department>
  </Employee>
  </Employees>

Lookup2.xml

  <?xml version="1.0" encoding="utf-8"?>
  <Employees>
     <Employee id="1">
     <Country code="10">Canada</Country>
     </Employee>
  </Employees>

I want a ouput insuch a way that I passed a comma seprated values to scripts e.g “Country,Department” and it should generate the following output

   <?xml version="1.0" encoding="utf-8" ?>
   <Employees>
   <Employee>
    <id name="id">1</id>
    <firstname >ABC</firstname>
    <lastname >XYZ</lastname>
    <age >32</age>
    <va-object>
    <va-metadata>
     <related-content-ref area="decisions"
        cite="102"
        relationship="department" relevance="100"/>
     <primary-class>
      <super-class super-class="value-add"/>
      <sub-class sub-class="department">HR</sub-class>
    </primary-class>
  </va-metadata>
</va-object>
<va-object>
  <va-metadata>
    <related-content-ref area="decisions"
        cite="10"
        relationship="country" relevance="100"/>
    <primary-class>
      <super-class super-class="value-add"/>
      <sub-class sub-class="country">Canada</sub-class>
    </primary-class>
  </va-metadata>
</va-object>
   </Employee>
   </Employees>

But if I just Pass “Country” as parameter then script should not insert Department or vice-versa.I can achive this by having 2 different tempaltes country and department but i want this to be achived by using one generic template with parametes from an external file. Any help will be appreciated.

  • 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-19T01:58:22+00:00Added an answer on May 19, 2026 at 1:58 am

    This stylesheet:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="kElemByParentId" match="Employee/*" use="../@id"/>
        <xsl:param name="pNames" select="'Country department'"/>
        <xsl:variable name="vNames" select="concat(' ',$pNames,' ')"/>
        <xsl:variable name="vLookup" select="document('Lookup1.xml')|
                                             document('Lookup2.xml')"/>
        <xsl:variable name="vUpper" select="'QWERTYUIOPASDFGHJKLZXCVBNM'"/>
        <xsl:variable name="vLower" select="'qwertyuiopasdfghjklzxcvbnm'"/>
        <xsl:template match="node()|@*" name="identity">
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="Employee/*[last()]">
            <xsl:variable name="vKey" select="../id"/>
            <xsl:call-template name="identity"/>
            <xsl:for-each select="$vLookup">
                <xsl:apply-templates select="key('kElemByParentId',$vKey)
                                              [contains($vNames,
                                                        concat(' ',name(),' '))]"
                                     mode="va-object"/>
            </xsl:for-each>
        </xsl:template>
        <xsl:template match="*" mode="va-object">
            <xsl:variable name="vName"
                          select="translate(name(),$vUpper,$vLower)"/>
            <va-object>
                <va-metadata>
                    <related-content-ref area="decisions"
                                         cite="{@code}"
                                         relationship="{$vName}"
                                         relevance="100"/>
                    <primary-class>
                        <super-class super-class="value-add"/>
                        <sub-class sub-class="{$vName}">
                            <xsl:value-of select="."/>
                        </sub-class>
                    </primary-class>
                </va-metadata>
            </va-object>
        </xsl:template>
    </xsl:stylesheet>
    

    Output:

    <Employees>
        <Employee>
            <id name="id">1</id>
            <firstname>ABC</firstname>
            <lastname>XYZ</lastname>
            <age>32</age>
            <va-object>
                <va-metadata>
                    <related-content-ref area="decisions"
                                         cite="102"
                                         relationship="department"
                                         relevance="100" />
                    <primary-class>
                        <super-class super-class="value-add" />
                        <sub-class sub-class="department">HR</sub-class>
                    </primary-class>
                </va-metadata>
            </va-object>
            <va-object>
                <va-metadata>
                    <related-content-ref area="decisions"
                                         cite="10"
                                         relationship="country"
                                         relevance="100" />
                    <primary-class>
                        <super-class super-class="value-add" />
                        <sub-class sub-class="country">Canada</sub-class>
                    </primary-class>
                </va-metadata>
            </va-object>
        </Employee>
    </Employees>
    

    Note: “Is in sequence” XPath 1.0 test:

    contains(concat($separator,$sequence,$separator),
             concat($separator,$item,$separator))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML input file and I'm trying to output the result of
I have an input file that I want to sort based on timestamp which
Say I have an input file, and a target directory. How do I determine
I have a file input element that needs to be cloned after the user
I need to delete my input file securely once I have finished with it,
Is there any way to have a Windows batch file directly input SQL statements
I have created a C# class file by using a XSD-file as an input.
I have a web page where it will input an excel/CSV file from the
Please help me to troubleshoot this problem. A have an input file 'Trial.txt' with
We have some input data that sometimes appears with &nbsp characters on the end.

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.