如何使用XSLT遍历字母?

问题描述 投票:0回答:1

我需要在XSLT 2.0中创建一个动态XSL-FO表,看起来与此类似:

+------+------+------+------+------+------+
|      |   1  |  2   |  3   |  4   |   5  |
+------+------+------+------+------+------+
|   A  |      |      |      |      |      |
+------+------+------+------+------+------+
|   B  |      |      |      |      |      |
+------+------+------+------+------+------+
|   C  |      |      |      |      |      |
+------+------+------+------+------+------+
|   D  |      |      |      |      |      |
+------+------+------+------+------+------+
|   E  |      |      |      |      |      |
+------+------+------+------+------+------+

两个端点(行,列)都是动态的,并用源数据中的最后一个数字/字母指定。

<input>
    <end-stop-column>5</end-stop-column>
    <end-stop-row>E</end-stop-row>
</input>

我想到了for-each方法(伪代码):

<fo:table>
    <fo:table-body>
        <fo:table-row>
            <fo:table-cell><fo:block></fo:block></fo:table-cell>
            <xsl:for-each select="1 to 5">
                <xsl:variable name="colid" select="current()"/>
                <fo:table-cell><fo:block><xsl:value-of select="$colid"/></fo:block></fo:table-cell>
            </xsl:for-each>
        </fo:table-row>
        <xsl:for-each select="A to E">
            <xsl:variable name="rowid" select="current()"/>
            <fo:table-row>
                <fo:table-cell><fo:block><xsl:value-of select="$rowid"/></fo:block></fo:table-cell>                    <xsl:for-each select="1 to 5">
                    <xsl:variable name="colid" select="current()"/>
                    <fo:table-cell>
                        <fo:block>
                            <xsl:text>Value for </xsl:text>
                            <xsl:value-of select="$rowid"/>
                            <xsl:text> </xsl:text>
                            <xsl:value-of select="$colid"/>
                        </fo:block>
                    </fo:table-cell>
                </xsl:for-each>
            </fo:table-row>
        </xsl:for-each>
    </fo:table-body>
</fo:table>

上面的XSLT不起作用,因为for-each上下文中的in只能处理数字。

如何处理行中的字母?这些行可能不会在Z处停止,而是从ZAZB,...,ZZZZA,....]重新开始

我需要在XSLT 2.0中创建一个动态XSL-FO表,该表类似于以下内容:+ ------ + ------ + ------ + ------ + ------ + ------ + | | 1 | 2 | 3 | 4 | 5 | + ------ + ------ + ------ + ------ + --...

xslt xslt-2.0 xsl-fo
1个回答
0
投票

如果string-to-codepoints(end-stop-row)足够(https://www.w3.org/TR/xpath-functions/#func-string-to-codepoints)(将取决于您所记住的字母),请使用从字母到数字的映射,请使用它。您可以用xsl:numberformat-number处理第二步中作为字母处理的数字格式。

© www.soinside.com 2019 - 2024. All rights reserved.