[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Re: XSL-FO: Creating Marginalias with Apache FOP


Subject: Re: [xsl] Re: XSL-FO: Creating Marginalias with Apache FOP
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 05 Nov 2010 10:07:10 -0400

At 2010-11-05 10:56 +0100, Gerhard Glatz wrote:
I corrected my xml:
(the number and order of maintextX and marginaliaX varies):

It was still not well formed. And I disambiguated the data values to illustrate the correct values were being used in the result.


My PDF output should look like this:

-----------------------------------------------
| <marginalia1> | (Nested table:) <title>     |
|               |-----------------------------|
|               | (Nested table:) <maintext1> |
|               |-----------------------------|
|               | (Nested table:) <maintext2> |
|---------------------------------------------|
| <marginalia2> | (Nested table:) <maintext2> |
|               |-----------------------------|
|               | (Nested table:) <maintext3> |
|---------------------------------------------|
| <marginalia3> | (Nested table:) <maintext4> |
-----------------------------------------------

Forgive me but I don't know what you want where you say "nested table:".


Yes, all of the elements have unique names.

I'm assuming they have to have something in common, say the prefix "marginalia", otherwise there is no determinant trigger.


As I said earlier, you need to use group-starting-with="" in order to infer structure from a flat set of constructs.

I hope the example below (in HTML) helps. I'll leave the XSL-FO as an exercise. The crux of your issue is how the XSLT works. When you look at the resulting HTML below you'll see your table as you've indicated above.

. . . . . . . . Ken


T:\ftemp>type gerhard.xml <root> ... <body> <marginalia1>number</marginalia1> <title>title</title> <body_info> <maintext1>ipsum lorem</maintext1> <maintext2>consectetur</maintext2>

      <marginalia2>ut enim2</marginalia2>
      <maintext2>consequat r2</maintext2>
      <maintext3>consequat r3</maintext3>

      <marginalia3>ut enim3</marginalia3>
      <maintext4>consequat r4</maintext4>
    </body_info>
  </body>
  ...
</root>

T:\ftemp>type gerhard.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

<xsl:output indent="yes"/>

<xsl:template match="/">
 <table border="1">
  <xsl:for-each-group select="/root/body/body_info/*"
      group-starting-with="*[starts-with(name(.),'marginalia')]">

    <xsl:choose>
      <xsl:when test="starts-with(name(.),'marginalia')">
        <!--then this is not the first grouping of the set-->
        <tr>
          <td rowspan="{count(current-group())-1}" valign="top"
             >
            <xsl:value-of select="."/>
          </td>
          <td>
            <xsl:value-of select="current-group()[2]"/>
          </td>
        </tr>
        <xsl:for-each select="current-group()[position()>2]">
          <tr>
            <td>
              <xsl:value-of select="."/>
            </td>
          </tr>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <!--this is the first grouping of the set-->
        <tr>
          <td rowspan="{count(current-group())+1}" valign="top"
             >
            <xsl:value-of select="../../marginalia1"/>
          </td>
          <td>
            <xsl:value-of select="../../title"/>
          </td>
        </tr>
        <xsl:for-each select="current-group()">
          <tr>
            <td>
              <xsl:value-of select="."/>
            </td>
          </tr>
        </xsl:for-each>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each-group>
 </table>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>xslt2 gerhard.xml gerhard.xsl
<?xml version="1.0" encoding="UTF-8"?>
<table border="1">
   <tr>
      <td rowspan="3" valign="top">number</td>
      <td>title</td>
   </tr>
   <tr>
      <td>ipsum lorem</td>
   </tr>
   <tr>
      <td>consectetur</td>
   </tr>
   <tr>
      <td rowspan="2" valign="top">ut enim2</td>
      <td>consequat r2</td>
   </tr>
   <tr>
      <td>consequat r3</td>
   </tr>
   <tr>
      <td rowspan="1" valign="top">ut enim3</td>
      <td>consequat r4</td>
   </tr>
</table>




-- Contact us for world-wide XML consulting & instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Legal business disclaimers: http://www.CraneSoftwrights.com/legal


Current Thread
Keywords