XSL-FO,将项目分组到表

时间:2013-08-29 00:17:01

标签: xslt xsl-fo xsl-grouping

XML:

<?xml version="1.0" encoding="utf-8"?>
<NewDataSet>
 <inc_incident>
  <inc_traumatriagecriteria>
    <TTC_ID>1    </TTC_ID>
    <TraumaTriageCriteria>(M)echanism: Ejection</TraumaTriageCriteria>
  </inc_traumatriagecriteria>
  <inc_traumatriagecriteria>
    <TTC_ID>2    </TTC_ID>
    <TraumaTriageCriteria>(M)echanism: Fatality</TraumaTriageCriteria>
  </inc_traumatriagecriteria>
  <inc_traumatriagecriteria>
    <TTC_ID>3    </TTC_ID>
    <TraumaTriageCriteria>(P)hysiologic: GCS</TraumaTriageCriteria>
  </inc_traumatriagecriteria>
  <inc_traumatriagecriteria>
    <TTC_ID>4    </TTC_ID>
    <TraumaTriageCriteria>(A)natomic: Crushed</TraumaTriageCriteria>
  </inc_traumatriagecriteria>
 </inc_incident>
</NewDataSet>

XSL:

<fo:table-body>
 <xsl:for-each select="inc_traumatriagecriteria">
  <fo:table-row>
   <fo:table-cell>
    <fo:block>
    <xsl:if test="contains(TraumaTriageCriteria, '(M)')">
      <xsl:value-of select="text()">    </xsl:value-of>
        </xsl:if>
   </fo:block>
    </fo:table-cell>
   <fo:block>
    <xsl:if test="contains(TraumaTriageCriteria, '(A)')">
   </xsl:if>
   </fo:block>
    </fo:table-cell>
   <fo:block>
     <xsl:if test="contains(TraumaTriageCriteria, '(P)')">
     </xsl:if>
   </fo:block>
</fo:table-cell>

使用xsl:if test =“contains(TraumaTriageCriteria,'(A)')”我得到的结果如下:

| MOI                  |   AI                  |        PC    |
===============================================================
|(M)echanism: Ejection |                      |              |
------------------------------------------------------------------
|(M)echanism: Fatality |                      |              |
-----------------------------------------------------------------
|                      |(A)natomic: Crushed  |(P)hysiologic: GCS |
-------------------------------------------------------------------

但希望我的表看起来像这样:

| MOI            | AI            | PC           |
=================================================
|(M)echanism: Ejection |(A)natomic: Crushed |(P)hysiologic: GCS|
-------------------------------------------------

有什么建议吗?

2 个答案:

答案 0 :(得分:1)

好的,没看,我看到你的XSL错了(参见你文档的以下副本中的评论):

  </fo:block>
  </fo:table-cell>
  <fo:block> <-- You are inserting a block with no table cell -->
   <xsl:if test="contains(TraumaTriageCriteria, '(A)')">
   </xsl:if> <-- No content in this if -->
   </fo:block>
   </fo:table-cell> <!-- No table cell created before this end table-cell -->
   <fo:block> <!-- again no table-cell here -->
   <xsl:if test="contains(TraumaTriageCriteria, '(P)')">
   </xsl:if> <!-- There is no content in this if -->
   </fo:block>
   </fo:table-cell> <!-- again no starting table-cell before this end -->

你应该将你的FO输出到一个很好的,解析一致的XML编辑器,看看所有的错误并纠正它们。

答案 1 :(得分:0)

                        <!--TRAUMA TRIAGE-->
          <xsl:if test="inc_incident/inc_situation/InjuryPresent = &quot;Yes&quot;">
            <xsl:for-each select="inc_incident">
              <fo:table start-indent="((8.5in - 0.5in - 0.5in) - 520pt) div 2" end-indent="((8.5in - 0.5in - 0.5in) - 520pt) div 2" background-color="silver" border-spacing="0" padding="0" text-align="center" width="520pt" table-layout="fixed" space-before.optimum="1pt" space-after.optimum="2pt">
                <fo:table-column />
                <fo:table-column />
                <fo:table-column />
                <fo:table-header>
                  <fo:table-row>
                    <fo:table-cell background-color="#5454A5" border-style="solid" border-width="1pt" border-color="silver" padding-start="0pt" padding-end="0pt" padding-before="0pt" padding-after="0pt" number-columns-spanned="3" text-align="center" display-align="center">
                      <fo:block>
                        <fo:inline color="white" font-family="Verdana, Arial, sans-serif" font-size="8pt" font-weight="bold">Trauma Triage</fo:inline>
                      </fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                    <fo:table-cell background-color="#eeeeee" border-style="solid" border-width="1pt" border-color="silver" padding-start="0pt" padding-end="0pt" padding-before="0pt" padding-after="0pt" display-align="center" text-align="center">
                      <fo:block>
                        <fo:inline font-family="Verdana, Arial, sans-serif" font-size="8pt" font-weight="bold">(M)echanism Of Injury</fo:inline>
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell background-color="#eeeeee" border-style="solid" border-width="1pt" border-color="silver" padding-start="0pt" padding-end="0pt" padding-before="0pt" padding-after="0pt" display-align="center" text-align="center">
                      <fo:block>
                        <fo:inline font-family="Verdana, Arial, sans-serif" font-size="8pt" font-weight="bold">(A)natomic Injury(ies)</fo:inline>
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell background-color="#eeeeee" border-style="solid" border-width="1pt" border-color="silver" padding-start="0pt" padding-end="0pt" padding-before="0pt" padding-after="0pt" display-align="center" text-align="center">
                      <fo:block>
                        <fo:inline font-family="Verdana, Arial, sans-serif" font-size="8pt" font-weight="bold">(P)hysiologic Criteria</fo:inline>
                      </fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                </fo:table-header>
                <fo:table-body>
                  <xsl:for-each select="inc_traumatriagecriteria">
                    <fo:table-row>
                      <fo:table-cell background-color="white" border-style="solid" border-width="1pt" border-color="silver" padding-start="0pt" padding-end="0pt" padding-before="0pt" padding-after="0pt" display-align="center" text-align="start">
                        <fo:block>
                          <xsl:if test="contains(TraumaTriageCriteria, '(M)')">
                            <xsl:for-each select="TraumaTriageCriteria">
                              <fo:inline font-family="Verdana, Arial, sans-serif" font-size="8pt">
                                <xsl:apply-templates />
                              </fo:inline>
                            </xsl:for-each>
                          </xsl:if>
                        </fo:block>
                      </fo:table-cell>
                      <fo:table-cell background-color="white" border-style="solid" border-width="1pt" border-color="silver" padding-start="0pt" padding-end="0pt" padding-before="0pt" padding-after="0pt" display-align="center" text-align="start">
                        <fo:block>
                          <xsl:if test="contains(TraumaTriageCriteria, '(A)')">
                            <xsl:for-each select="TraumaTriageCriteria">
                              <fo:inline font-family="Verdana, Arial, sans-serif" font-size="8pt">
                                <xsl:apply-templates />
                              </fo:inline>
                            </xsl:for-each>
                          </xsl:if>
                        </fo:block>
                      </fo:table-cell>
                      <fo:table-cell background-color="white" border-style="solid" border-width="1pt" border-color="silver" padding-start="0pt" padding-end="0pt" padding-before="0pt" padding-after="0pt" display-align="center" text-align="start">
                        <fo:block>
                          <xsl:if test="contains(TraumaTriageCriteria, '(P)')">
                            <xsl:for-each select="TraumaTriageCriteria">
                              <fo:inline font-family="Verdana, Arial, sans-serif" font-size="8pt">
                                <xsl:apply-templates />
                              </fo:inline>
                            </xsl:for-each>
                          </xsl:if>
                        </fo:block>
                      </fo:table-cell>
                    </fo:table-row>
                  </xsl:for-each>
                </fo:table-body>
              </fo:table>
            </xsl:for-each>
          </xsl:if>