xml - Initial number part or integer portion of a string in xsl -
by using xsl template, can 1 tell me way first number portion of string field
for example:
'12' -> should result in -> 12 '5 asdf' -> should result in -> 5 '34sdf56' -> should result in -> 34
here one-liner xpath solution: :)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="text"/> <xsl:template match="text()"> <xsl:variable name="vs" select="concat(.,'z')"/> <xsl:value-of select= "substring-before(translate($vs,translate($vs,'0123456789',''),'z'),'z')"/> <xsl:text>
</xsl:text> </xsl:template> </xsl:stylesheet>
when transformation applied on following xml document:
<t> <x>12</x> <x>5 asdf</x> <x>34sdf56</x> </t>
the wanted, correct results produced:
12 5 34
Comments
Post a Comment