如何使用 XSLT 遍历字母表?

How to loop through the alphabet with XSLT?

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

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

两个终止点(行、列)都是动态的,并由源数据中的最后一个 number/letter 指定。

<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-eachin 上下文中只能处理数字。

如何处理行中的字母?行可能不会在 Z 处停止并从 ZAZB、...、ZZZZA、....[=21 重新开始=]

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

处理