I am trying to convert the value of an XML element to another format, such as KG, in LBS. Say I have XML
<all>
<one>Something 1</one>
<two>something 2</two>
<check>
<present>true</present>
</check>
<action>
<perform></perform>
</action>
<a>
<Weight>1Kg</Weight>
</a>
</all>
after XSLT my expected result
<?xml version="1.0" encoding="UTF-8"?><all>
<one>Something 1</one>
<two>something 2</two>
<check>
<present>true</present>
</check>
<action>
<perform/>
</action>
<a>
<UNIT-WEIGHT>2.2046226218487757</UNIT-WEIGHT>
</a>
</all>
for this I write
<xsl:template match= "@*|node()" >
<xsl:copy>
<xsl:apply-templates select= "@*|node()" />
</xsl:copy>
</xsl:template >
<xsl:template match="Weight">
<UNIT-WEIGHT>
<xsl:value-of select=". div 0.45359237"/>
</UNIT-WEIGHT>
</xsl:template>
If <Weight>1</Weight>, I get my desired result, and if <Weight>1Kg</Weight>, I get<UNIT-WEIGHT>NaN</UNIT-WEIGHT>
What should I do?
user6633569
source
share