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=" ">
Your example file is not well formed, but if you fix that, and your property file is prop.xml, this should work:
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
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
defelement then a minor modification as follows: