views:

27

answers:

1

Using Perl's XML::LibXSLT necessitates that I use XSLT 1.0, which means that I am stuck without XSLT 2.0 features. Is there a way that I can still pad text cleanly in a plain-text output from my processing? What I want is:

<values>
    <headers>
        <header>Header 1</header>
        <header>Header 2</header>
    </headers>
    <value>
        <one>First value 1</one>
        <two>First value 2</two>
    </value>
    <value>
        <one>Second value 1</one>
        <two>Second value 2</two>
    </value>
    ....
    <value>
        <one>Nth value 1</one>
        <two>Nth value 2</two>
    </value>
</values>

To become

Header 1          Header 2
First value 1     First value 2
Second value 1    Second value 2
....
Nth value 1       Nth value 2

I realize that XSLT isn't necessarily ideally suited for this type of formatting, but the data will likely also be formatted in other ways.

+1  A: 

There is always the "cheap" way of padding text by having a constant string and doing a copy of the count needed to pad, like this:

<xsl:variable name="space" select='                     '" />
<xsl:variable name="text" select='Header 1'" />
<xsl:value-of select="concat($text,substring($space,string-length($text)))" />
Lucero
Works like a charm, thank you.
justkt
Don't you have to use preserve-space here? Just asking. http://www.w3schools.com/xsl/el_preserve-space.asp
AJ
@AJ: No. Note that the output requested in the question is text, not XML or HTML.
Lucero