Need XLST to change value of a node based on another node
I need XSLT to change the value of Enabled
to False
if the Name
is XYZ
in the below XML file.
My XML file is:
<MyRoot>
<Category>
<Name>XYZ</Name>
<Location>mylocation</Location>
<Enabled>True</Enabled>
</Category>
<Category>
<Name>ABC</Name>
<Location>mylocation1</Location>
<Enabled>True<开发者_运维百科;/Enabled>
</Category>
<Category>
<Name>DEF</Name>
<Location>mylocation2</Location>
<Enabled>True</Enabled>
</Category>
</MyRoot>
This is how I would handle it:
XSLT
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Category[Name='ABC']/Enabled">
<Enabled>False</Enabled>
</xsl:template>
</xsl:stylesheet>
output
<MyRoot>
<Category>
<Name>XYZ</Name>
<Location>mylocation</Location>
<Enabled>False</Enabled>
</Category>
<Category>
<Name>ABC</Name>
<Location>mylocation1</Location>
<Enabled>True</Enabled>
</Category>
<Category>
<Name>DEF</Name>
<Location>mylocation2</Location>
<Enabled>True</Enabled>
</Category>
</MyRoot>
精彩评论