3

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.

justkt
  • 14,610
  • 8
  • 42
  • 62

1 Answers1

2

There is always the "cheap" way of padding text by using 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)))" />
Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
Lucero
  • 59,176
  • 9
  • 122
  • 152
  • Don't you have to use preserve-space here? Just asking. http://www.w3schools.com/xsl/el_preserve-space.asp –  May 17 '10 at 17:20
  • 1
    @AJ: No. Note that the output requested in the question is text, not XML or HTML. – Lucero May 17 '10 at 23:07