Saturday, 10 January 2015

Change value in XML tag using XSLT according to the attribute value



I am new to XSL and I am stuck with a problem.


I have an xml of the following format:



<Destinations>
<conf:Destination id="12">
<conf:attributes>
<conf:attribute1>1212</conf:attribute1>
</conf:attributes>
</conf:Destination>
<conf:Destination id="31">
<conf:attributes>
<conf:attribute1>3131</conf:attribute1>
</conf:attributes>
</conf:Destination>
</Destinations>


And say, I have an xsl with following 2 params:



<xsl:param name="attribute12" select="'21'" />
<xsl:param name="attribute31" select="'5'" />


I want to have a xsl template in XSLT 1 that changes my xml as follows: 1) For destination id=12 in xml, value inside 'conf:attribute1' tag to be set as 21 2) For destination id=31 in xml, value inside 'conf:attribute1' tag to be set as 5


This way I will have final xml as:



<Destinations>
<conf:Destination id="12">
<conf:attributes>
<conf:attribute1>21</conf:attribute1>
</conf:attributes>
</conf:Destination>
<conf:Destination id="31">
<conf:attributes>
<conf:attribute1>5</conf:attribute1>
</conf:attributes>
</conf:Destination>
</Destinations>


Can anybody please help.


No comments:

Post a Comment