xml - How to insert a missing element or modify an existing element? -
i working on xml & xslt dynamic value has generate.
my xml
<query> <one>testing1</one> <one>testing1</one> </query>
my output xml
<query> <one>testing1</one> <one>testing1</one> <sample>100</sample> </query>
xslt need check(xsl:if)whether sample element available or not input xml if available 10% have remove % using xslt output 10. if there no element in xml(sample) has create default 100.
can able in xslt possible.
can me out here please
regards m
how ...
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="/*[not(//sample)]"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> <sample>100</sample> </xsl:copy> </xsl:template> <xsl:template match="sample"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:value-of select="translate(.,'%','')"/> <xsl:apply-templates select="*"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
explanation
the second template adds sample node, if not present. third template removes percentage signs existing samples.
Comments
Post a Comment