Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XSLT function for padding value with characters >Thread Next - Re: XSLT function for padding value with characters Re: XSLT function for padding value with charactersTo: NULL Date: 5/3/2007 3:47:00 PM Chip Pearson wrote: > I am considering using XSLT to take existing XML data files and creating > text files that will be imported to other programs. These import files must > be formatted text not XML. For example, vendor numbers must be 12 digits > padded on the left with 0's and product names must be 30 characters padded > on the right with spaces. Is there a way using XSLT to pad out a value to a > specified length using a specified padding character? I can't have the > formatted values in the XML data itself because one XML node value will be > going to multiple output text files each with its own formatting > requirements. <xsl:param name="spaces" select=" "/> <!-- 30 space characters --> Now if you have an element ProductName you can do e.g. <xsl:value-of select="concat(ProductName, substring($spaces, 1, 30 - string-length(ProductName)))"/> You could put that stuff in a template and call it as needed. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
