XSLT 为 Apache FOP 生成动态列 [英] XSLT Generate Dynamic Columns for Apache FOP

查看:23
本文介绍了XSLT 为 Apache FOP 生成动态列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个包含 3 列区域的动态表

I need to make a dynamic table with 3 columns zones

最好举个例子:我不知道你是否会理解这一点,但----"只是为了格式化帖子中的表格

Is better with an example: I don't know if you are gonna understand this, but the "----" is only to format the table in the post

|--Number--|--Doc--|--Status---------|--Number--|--Doc--|--Status---------|--编号--|--文档--|--状态--||-----11------|1111- |-- _____________---------|--22------- |2222 --|______________-----------|---- 33----- |3333- |_______________|

|--Number--|--Doc--|--Status---------|--Number--|--Doc--|--Status---------|--Number--|--Doc--|--Status--| |-----11------|1111- |-- _____________---------|--22------- |2222 --|______________----------|---- 33----- |3333- | _______________|

|-----44----- |4444- |-- _____________ -------- |------------|----------|---------|---------|--------------|---------|------------|

|-----44----- |4444- |-- _____________ -------- |------------|----------|----------|---------|--------------|---------|------------|

我的 XML:

    <Details>
      <Detail>
        <Number>11</Number> 
        <Doc>1111</Doc>
      </Detail>
      <Detail>
        <Number>22</Number> 
        <Doc>2222</Doc> 
      </Detail>
      <Detail>
        <Number>33</Number> 
        <Doc>3333</Doc> 
      </Detail>
      <Detail>
        <Number>44</Number> 
        <Doc>4444</v> 
      </Detail>
    </Details>

我试着像下面的帖子那样做,但我做不到.XSLT 为 Apache FOP 生成动态行和列

I tried to do like following post but I couldn't. XSLT Generate Dynamic Rows and Columns for Apache FOP

推荐答案

这是递归的一种方式,我没有添加FO"命名空间,但您应该能够使用它到达那里.如果您愿意,还可以添加一个测试来填充空单元格.

Here's one way with recursion, I did not add "FO" namespaces but you should be able to get there using this. You could also add a test to fill empty cells if you are inclined.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="Details">
   <table>
    <xsl:call-template name="rows">
        <xsl:with-param name="Details" select="*"/>
    </xsl:call-template>
   </table>
</xsl:template>
<xsl:template name="rows">
    <xsl:param name="Details"/>
    <row>
        <xsl:apply-templates select='$Details[position() &lt; 4]/*'/>
    </row>
    <xsl:if test="$Details[4]">
        <xsl:call-template name="rows">
            <xsl:with-param name="Details" select="$Details[position() &gt; 3]"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>
<xsl:template match="Number | Doc">
    <cell>
        <xsl:value-of select="."/>
    </cell>
</xsl:template>
</xsl:stylesheet>

使用上面的 XML 输出是这样的(我添加了更多 Detail 元素以确保一切正常):

The output is this using your XML above (I added a few more Detail elements to make sure all was working):

<?xml version="1.0" encoding="utf-8"?>
<table>
  <row>
      <cell>11</cell>
      <cell>1111</cell>
      <cell>22</cell>
      <cell>2222</cell>
      <cell>33</cell>
      <cell>3333</cell>
   </row>
   <row>
      <cell>44</cell>
      <cell>4444</cell>
      <cell>5</cell>
      <cell>55</cell>
      <cell>6</cell>
      <cell>66</cell>
   </row>
   <row>
      <cell>7</cell>
      <cell>777</cell>
   </row>
 </table>

这篇关于XSLT 为 Apache FOP 生成动态列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆