Formatting string (Removing leading zeros)

后端 未结 8 2053
鱼传尺愫
鱼传尺愫 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 10:57

    All XSLT1 parser, like the popular libXML2's module for XSLT, have the registered functions facility... So, we can suppose to use it. Suppose also that the language that call XSLT, is PHP: see this wikibook about registerPHPFunctions.


    The build-in PHP function ltrim can be used in

      
      
       
       
           show ",
       
      
    

    Now imagine a little bit more complex problem, to ltrim a string with more than 1 number, ex. hello 002 and 021, bye.

    The solution is the same: use registerPHPFunctions, except to change the build-in function to a user defined one,

    function ltrim0_Multi($s) {
        return preg_replace('/(^0+|(?<= )0+)(?=[1-9])/','',$s);
    } 
    

    converts the example into hello 2 and 21, bye.

提交回复
热议问题