This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > May 2007 > XSLT function for padding value with characters
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
XSLT function for padding value with characters
|
|
| Chip Pearson 2007-05-03, 6:16 pm |
| 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.
Any suggestions would be most welcome. Thank you very much.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting LLC
www.cpearson.com
(email on the web site)
| |
| Martin Honnen 2007-05-03, 6:16 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/
| |
| Chip Pearson 2007-05-06, 6:18 pm |
| Martin,
Thank you for the reply. I finally got it to work once I figured out that
the spaces in the select must be enclosed in single-quote (apostrophe)
characters.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting LLC
www.cpearson.com
(email on the web site)
"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:eG7XImYjHHA.4032@TK2MSFTNGP02.phx.gbl...
> Chip Pearson wrote:
>
> <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/
| |
| Martin Honnen 2007-05-07, 6:17 pm |
| Chip Pearson wrote:
> I finally got it to work once I figured out that
> the spaces in the select must be enclosed in single-quote (apostrophe)
> characters.
Right, it seems my example lacked the quotes, sorry about that.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|