Monday, September 19, 2022

XSLT Mapping - Extract Integer value

 I had a requirement where in we wanted to extract the km value from a node value.


Input XML Example:

-------------------------------------------------------------------------------

<root>

<test>Nasik 180km Bombay</test>

</root>




-------------------------------------------------------------------------------


XSLT Mapping used:

-------------------------------------------------------------------------------

<xsl:stylesheet version="1.0"

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:strip-space elements="*"/>


 <xsl:template match="/*">

     <xsl:value-of select=

      "translate(.,translate(., '0123456789', ''), '')"/>

 </xsl:template>

</xsl:stylesheet>


-------------------------------------------------------------------------------





Output:





-------------------------------------Love Your Fate ----------------------------------------------------------

No comments:

Post a Comment