XSL-FO, Group items to tables

619 views Asked by At

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>

with xsl:if test="contains(TraumaTriageCriteria, '(A)')" I get result like this:

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

but would like my table to look like this:

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

Any suggestion?

2

There are 2 answers

1
Kevin Brown On

Well without looking, I see you XSL is wrong (see the comments in the following copy of your document):

  </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 -->

You should output your FO to a nice, parsing conforming XML editor and look at all the mistakes and correct them.

2
user2726752 On
                        <!--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>