문제

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.

도움이 되었습니까?

해결책

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)))" />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top