I know that generating fixed width text from XMl is a common need. And I know this question has been asked before, but every answer I've found is unclear to me due to my lack of understand of XSLT functions.
I have several examples of using an XSLT function to pad a string to a particular width. But none of the examples I'f found are very clear on how to use these functions.
I need to take the contents of an XML element, and pad that to a fixed with with spaces. I have found such functions at the below links.
- http://www.xsltfunctions.com/xsl/functx_pad-string-to-length.html
- XSL left-right justification with Padding
- http://www.exslt.org/str/functions/padding/str.padding.template.xsl.html
But in each example they pass in a string, such as "1234 Street". How do I use such functions by passing an element such as <Address>1234 Street</Address>
1234 Streetis a string, not an element.<StreetAddress>1234 Street</StreetAddress>is an element - and you would use<xsl:value-of select="StreetAddress"/>to get the element's text value and pass it to a string function.string-function(StreetAddress)ends up being the same thing asstring-function("1234 Street"). This is probably the more frequent form of use you will see.{}to format them.