I need to change the value of a specific node element in an xml file via xsl. Below is my xml data.
<hospitals> <hospital> <department> <clinic> <cid>8</cid> <clinicName>clinic8</clinicName> <status>1</status> </clinic> <clinic> <cid>9</cid> <clinicName>clinic9</clinicName> <status>0</status> </clinic> <depId>3</depId> <departmentName>dental</departmentName> </department> <hospId>2</hospId> <hospitalName>appolo</hospitalName> </hospital> <hospital> <department> <clinic> <cid>82</cid> <clinicName>clinic82</clinicName> <status>0</status> </clinic> <clinic> <cid>92</cid> <clinicName>clinic92</clinicName> <status>0</status> </clinic> <depId>4</depId> <departmentName>mental</departmentName> </department> <hospId>2</hospId> <hospitalName>manipal</hospitalName> </hospital> </hospitals>
for example, I need to select clinic9 based on its id ie 9 and change the status 0 to 1
I tried like this
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="hospId"/> <xsl:param name="depId" /> <xsl:param name="clinicId"/> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="hospitals/hospital[hospId='2']/department[depId='3']/clinic[cid='9']"> <xsl:choose> <xsl:when test="cid ='9'"> <xsl:element name="status">123</xsl:element> </xsl:when> </xsl:choose> </xsl:template> </xsl:stylesheet>
But the meaning does not change ...
source share