XSLT 1 纯文本间距

发布于 2024-09-02 12:01:05 字数 855 浏览 5 评论 0原文

使用 Perl 的 XML::LibXSLT 需要我使用 XSLT 1.0,这意味着我无法使用 XSLT 2.0 功能。有没有办法让我仍然可以在处理的纯文本输出中干净地填充文本?我想要的是:

<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>

成为

标头 1 标头 2
第一个值 1 第一个值 2
第二个值 1 第二个值 2
....
第 N 个值 1 第 N 个值 2

我意识到 XSLT 不一定非常适合这种类型的格式化,但数据也可能以其他方式格式化。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汹涌人海 2024-09-09 12:01:05

总是有一种“便宜”的方法来填充文本,即使用常量字符串并复制填充所需的计数,如下所示:

<xsl:variable name="space" select="'                     '" />
<xsl:variable name="text" select="'Header 1'" />
<xsl:value-of select="concat($text,substring($space,string-length($text)))" />

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)))" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文