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

查看:65
本文介绍了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天全站免登陆