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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:12:35+00:00 2026-06-01T15:12:35+00:00

If you store the properties file in XML format, for instance <Properties> <Property value=abc>ABC1</Property>

  • 0

If you store the properties file in XML format, for instance

<Properties>
    <Property value="abc">ABC1</Property>
    <Property value="...">...</Property>
</Properties>

then we can use xslt to process both(properties,input) XML files and replace abc elements(of input xml file) with ABC1(of custom output xml file) ones, etcetera.

for example consider my below input xml file

<?xml version="1.0" encoding="UTF-8"?>
       <Content>
          <abc>xxx
                 <def>zzz
                    <ghi>ccc</ghi>ttt
                     <dynamic val="hello" xmlns="http://abc.com" />
                      world
                     <dynamic val="hi" xmlns="http://abc.com" />
                       <dynAttr>
                         <dyn value=123 />
                         <dyn value=222 />
                       </dynAttr>
                         <lmn>data</lmn>

                   </def>
                </abc>
         </Content>

with Properties file consisting of a property defined for each tag of input xml file,if no property defined for that input xml file tag then transformed xml tag has the same tag name to that of input xml file tag.

<?xml version="1.0" encoding="UTF-8"?>
<Properties>
             <Property value="Content">CONTENT12</Property>
             <Property value="abc">ABC1</Property>
             <Property value="def">www</Property>
              <Property value="ghi">yyy</Property>
             <Property value="dynamic">Dynamic1</Property>
             <Property value="dynAttr">DynAttribute</Property>
</Properties>

using xslt and writing an xsl file which refers the properties xml file and when applied on the given input xml file and results in the transformed xml file as shown

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

                <www>zzz
                    <yyy>ccc</yyy>ttt
                     <Dynamic1 val="hello" xmlns="http://abc.com>hello</Dynamic1>
                      world
                     <Dynamic1 val="hi" xmlns="http://abc.com>hi</Dynamic1>
                       <DynAttribute>
                         <dyn>123</dyn>
                         <dyn>222</dyn>
                       </DynAttribute>
                         <lmn>data</lmn>
                   </www>
if the above code is my requirement then what must be the relative xpath expression in your answer <xsl:template match=" ">
  • 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-01T15:12:36+00:00Added an answer on June 1, 2026 at 3:12 pm

    Your example file is not well formed, but if you fix that, and your property file is prop.xml, this should work:

    <xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    
    <xsl:template match="*">
     <xsl:variable name="n" select="name()"/>
     <xsl:variable name="new">
      <xsl:for-each select="document('prop.xml')">
       <xsl:choose>
        <xsl:when test="key('n',$n)">
         <xsl:value-of select="key('n',$n)"/>
        </xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="$n"/>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:for-each>
     </xsl:variable>
     <xsl:element name="{$new}">
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
     </xsl:element>
    </xsl:template>
    
    <xsl:key name="n" match="Property" use="@value"/>
    
    </xsl:stylesheet>
    

    Your question does not say what namespace renamed elements should be in. the above code always puts them in no-namespace. If you want them to be in the same namespace as the original change the xsl:element line to

     <xsl:element name="{$new}" namespace="{namespace-uri()}">
    

    The most flexible alternative would probably be to specify both the local name and namespace uri in the properties file.

    update

    If as noted in the comments and the updated answer you want to preserve namespaces and only process the def element then a minor modification as follows:

    <xsl:stylesheet version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    
    <xsl:template match="/">
     <xsl:apply-templates select="//def"/>
    </xsl:template>
    
    <xsl:template match="*">
     <xsl:variable name="n" select="name()"/>
     <xsl:variable name="new">
      <xsl:for-each select="document('prop.xml')">
       <xsl:choose>
        <xsl:when test="key('n',$n)">
         <xsl:value-of select="key('n',$n)"/>
        </xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="$n"/>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:for-each>
     </xsl:variable>
     <xsl:element name="{$new}" namespace="{namespace-uri()}">
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
     </xsl:element>
    </xsl:template>
    
    <xsl:key name="n" match="Property" use="@value"/>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use XML file to store each key/value pair used by my
I'd like to store a properties file as XML. Is there a way to
I was initially going to use a signed serialized xml file to store license
I use a table GadgetData to store the properties of gadgets in my application.
I've got a class with several properties. On every value update, a Store method
I was using a properties.xml file which i stored with java.util.properties storeToXML. but storeToXML
I need to store some simple properties in a file and access them from
Basically I have a single element inside of an xml file where I store
I have a process that parses an XML file using JDOM and xpath to
Basically, I have to overwrite a certain property in a .properties file through a

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.