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>&#xa;</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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -