Formatting string (Removing leading zeros)

后端 未结 8 2054
鱼传尺愫
鱼传尺愫 2021-01-11 10:07

I am newbie to xslt. My requirement is to transform xml file into text file as per the business specifications. I am facing an issue with one of the string formatting issue.

8条回答
  •  臣服心动
    2021-01-11 11:11

    There are a couple of ways you can do this. If the value is entirely numeric (for example not a CSV line or part of a product code such as ASN0012345) you can convert from a string to a number and back to a string again :

    string(number($value)).
    

    Otherwise just replace the 0's at the start :

    replace( $value, '^0*', '' )
    

    The '^' is required (standard regexp syntax) or a value of 001201 will be replaced with 121 (all zero's removed).

    Hope that helps. Dave

提交回复
热议问题