>我需要在 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 不起作用,因为in
上下文中的for-each
只能处理数字。
如何处理行中的字母?行可能不会在Z
处停止,而是从ZA
、ZB
、...、ZZ
、ZZA
、
使用从字母到数字的映射,如果string-to-codepoints(end-stop-row)
足够(https://www.w3.org/TR/xpath-functions/#func-string-to-codepoints((将取决于你想到的字母表(,使用它。在第二步中将数字格式处理为字母可以通过xsl:number
或format-number
处理。