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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:40:25+00:00 2026-06-15T02:40:25+00:00

i have some requirement, where i need to replace the references in the same

  • 0

i have some requirement, where i need to replace the references in the same xml file.
limitation is to use xslt 1.0 only.

below is my sample input xml.

    <org>
       <depts>
          <dept>
             <deptId>1009</deptId>
                <deptName>IT</deptName>
                <deptAccessCode>IT-1009</deptAccessCode>
          </dept>
          <dept>
             <deptId>2344</deptId>
             <deptName>BPO</deptName>
             <deptAccessCode>BP-2344</deptAccessCode>
          </dept>
          </depts>
          <employees>
             <employee>
             <name>abc</name>
             <dept>
              <REFERENCE>
                 <LocationXPath>/org/depts/dept[2]</LocationXPath>
              </REFERENCE>
          </dept>
          <employee>
       </employees>
</org>

now i want to replace the node REFERENCE with actual data at the XPath /org/depts/dept[2].
so the output xml should be like below.

    <org>
       <depts>
          <dept>
             <deptId>1009</deptId>
                <deptName>IT</deptName>
                <deptAccessCode>IT-1009</deptAccessCode>
          </dept>
          <dept>
             <deptId>2344</deptId>
             <deptName>BPO</deptName>
             <deptAccessCode>BP-2344</deptAccessCode>
          </dept>
          </depts>
          <employees>
             <employee>
             <name>abc</name>
             <dept>
             <deptId>2344</deptId>
             <deptName>BPO</deptName>
             <deptAccessCode>BP-2344</deptAccessCode>
          </dept>
          <employee>
       </employees>
    </org>

i have several REFERENCE nodes in different elements referencing to different xpaths across the xml tree, which i need to replace them with actual data.

<someWhereInTheXmlTree>
<sometag>
   <REFERENCE>
      <LocationXPath>some/reference[1]/to/a/node[3]/in/the[4]/same/xml</LocationXPath>
   </REFERENCE>
</sometag>
<someWhereInTheXmlTree>
...
<ffff>
<bbbb>
   <REFERENCE>
      <LocationXPath>abc/xyz[1]/node[4]/element</LocationXPath>
   </REFERENCE>
</bbbb>
<ffff>

please help me on this.
Thanks in advance for the help.

So far i have implemented one XSLT to replace the references but now i am facing unwanted empty name spaces.

Here is my XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tib="http://www.tibco.com/bw/xslt/custom-functions"
xmlns="http://www.realestate.org/residential/2010/schemas" >

<xsl:output omit-xml-declaration="no" indent="yes" method = "xml" />
<xsl:strip-space elements="*"/>
<xsl:param name="myxml"  />
<xsl:template match="node()|@*">
    <xsl:param name="isNodeToReplace"><xsl:call-template name="ReferenceCheck" /></xsl:param>
    <xsl:choose>
        <xsl:when test="$isNodeToReplace='true'">
            <xsl:call-template name="replaceWithData">
                <xsl:with-param name="ref"><xsl:value-of select="." /></xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="ReferenceCheck">
    <xsl:choose>
        <xsl:when test="name(child::*[1])='REFERENCE' and name(child::*[1]//child::*[1])='LocationXPath'">true</xsl:when>
        <xsl:otherwise>false</xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="replaceWithData">
    <xsl:param name="ref" />
    <xsl:copy-of select="tib:evaluate($myxml,$ref)" />
</xsl:template>

</xsl:stylesheet>

in the above XSLT i am passing the entire xml (same xml, which is being processed) as a parameter $myxml

Below is my sample input XML –this is just a snippet of xml,The actual xml file which i am dealing with is too large and contains so complex tree structure.How ever this sample xml is suffice enough to produce my problem.

Input file

<?xml version="1.0" encoding="UTF-8"?>
<org xmlns="http://www.realestate.org/residential/2010/schemas">
    <depts>
        <dept>
            <deptId>1</deptId>
            <deptName>health</deptName>
            <deptAccessCode>HL007845</deptAccessCode>
        </dept>
    </depts>
    <employees>
        <employee>
            <name>TOM</name>
            <dept>
                <REFERENCE>
                    <LocationXPath>/org/depts/dept[1]</LocationXPath>
                </REFERENCE>
            </dept>
        </employee>
    </employees>
</org>

my output file

<?xml version="1.0" encoding="UTF-8"?>
<org xmlns="http://www.realestate.org/residential/2010/schemas">
    <depts>
        <dept>
            <deptId>1</deptId>
            <deptName>health</deptName>
            <deptAccessCode>HL007845</deptAccessCode>
        </dept>
    </depts>
    <employees>
        <employee>
            <name>TOM</name>
            <dept xmlns="">
                <deptId>1</deptId>
                <deptName>health</deptName>
                <deptAccessCode>HL007845</deptAccessCode>
            </dept>
        </employee>
    </employees>
</org>  

Where as Expected output

<?xml version="1.0" encoding="UTF-8"?>
<org xmlns="http://www.realestate.org/residential/2010/schemas">
    <depts>
        <dept>
            <deptId>1</deptId>
            <deptName>health</deptName>
            <deptAccessCode>HL007845</deptAccessCode>
        </dept>
    </depts>
    <employees>
        <employee>
            <name>TOM</name>
            <dept>
                <deptId>1</deptId>
                <deptName>health</deptName>
                <deptAccessCode>HL007845</deptAccessCode>
            </dept>
        </employee>
    </employees>
</org>

so i am getting unwanted empty name space in << dept xmlns=””>> in the replaced root element.
Hope this could clearly explain my problem
Thanks in Advance

ultimately i have found the solution at the link below to remove the unwanted empty name spaces.
http://social.msdn.microsoft.com/forums/en-US/xmlandnetfx/thread/0de59291-ef3a-4a4c-9ca5-17923b16a504

Here is the new XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tib="http://www.tibco.com/bw/xslt/custom-functions"
xmlns="http://www.realestate.org/residential/2010/schemas" >

<xsl:output omit-xml-declaration="no" indent="yes" method = "xml" />
<xsl:strip-space elements="*"/>
<xsl:param name="myxml"  />
<xsl:template match="node()|@*">
    <xsl:param name="isNodeToReplace"><xsl:call-template name="ReferenceCheck" /></xsl:param>
    <xsl:choose>
        <xsl:when test="$isNodeToReplace='true'">
            <xsl:call-template name="replaceWithData">
                <xsl:with-param name="ref"><xsl:value-of select="." /></xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:copy>
                <xsl:apply-templates select="node()|@*"/>
            </xsl:copy>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="ReferenceCheck">
    <xsl:choose>
        <xsl:when test="name(child::*[1])='REFERENCE' and name(child::*[1]//child::*[1])='LocationXPath'">true</xsl:when>
        <xsl:otherwise>false</xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="replaceWithData">
    <xsl:param name="ref" />
    <xsl:apply-templates select="tib:evaluate($myxml,$ref)" mode="move-to-namespace">
        <xsl:with-param name="namespace" select="'http://www.realestate.org/residential/2010/schemas'" />
    </xsl:apply-templates>
</xsl:template>
<xsl:template match="*" mode="move-to-namespace">
    <xsl:param name="namespace" />
    <xsl:element name="{local-name()}" namespace="{$namespace}">
        <xsl:copy-of select="@*" />
        <xsl:apply-templates select="node()" mode="move-to-namespace">
            <xsl:with-param name="namespace" select="$namespace"/>
        </xsl:apply-templates>
    </xsl:element>
</xsl:template>

<xsl:template match="text() | comment() | processing-instruction()" mode="move-to-namespace">
    <xsl:copy/>
</xsl:template>

</xsl:stylesheet>

if any xslt expert refines it further to avoid any unnecessary instruction with proper explanation its very glad.

Thanks in advance

  • 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-15T02:40:27+00:00Added an answer on June 15, 2026 at 2:40 am

    In general:

    • Not posiible in pure XSLT 1.0.

    • Not possible in pure XSLT 2.0

    • May be possible in pure XSLT 3.0 — read about the
      <xsl:evaluate> instruction.

    • In XSLT 1.0 you may be lucky if your XSLT processor implements the EXSLT dyn:evaluate() extension function (a few do).
      Otherwize, you will have to write an extension function to select the
      nodes and return them back.

    If there are restrictions on the syntax of the XPath expressions, then it may be possible to implement a pure XSLT 1.0 solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following requirement: Based on some user input, I need to generate
I have some what complex UI requirement, need help in understanding type of control/style/template
SO buddies, greetings. I have some password requirements I need to implement and one
I have some webserver resources protected with Form based Authentication. The requirement is to
I have requirement where some times I would like to load children as well
We have a business requirement that some users be automatically logged out of our
I have this problem containing some inequations and requirement to minimize a value. After
I have a requirement to do some imports from an Excel spread sheet and
My requirement is to work on some interface .h files. Right now I have
i have one database, and it contains some columns. My requirement is that how

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.