<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.1" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:fo="http://www.w3.org/1999/XSL/Format" 
	exclude-result-prefixes="fo">

  <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>

  <!-- ================== -->
  <!-- root element: user -->
  <!-- ================== -->

  <xsl:template name="user" match="user">

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" 
	page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm">
          <fo:region-body/>				
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="simpleA4">

        <!-- START MAIN BODY -->
        <fo:flow flow-name="xsl-region-body">

          <!-- Title Text -->
	  <fo:block font-weight="bold" text-align="start" space-after="12pt">
            User Report
          </fo:block>

          <!-- START MAIN TABLE -->
          <fo:block>
            <fo:table table-layout="fixed" border="solid black 1px">
              <fo:table-column column-width="4.3cm" column-number="1"/>
              <fo:table-column column-width="4.3cm" column-number="2"/>

              <fo:table-body>

                <fo:table-row>
                  <fo:table-cell font-weight="bold" padding="2px" border="solid black 1px">
                    <fo:block>
                      First name 
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2px" border="solid black 1px">
                    <fo:block>
                      <xsl:value-of select="firstName"/>
                    </fo:block>
                  </fo:table-cell>
                </fo:table-row>

                <fo:table-row>
                  <fo:table-cell font-weight="bold" padding="2px" border="solid black 1px">
                    <fo:block>
                      Last name 
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2px" border="solid black 1px">
                    <fo:block>
                      <xsl:value-of select="lastName"/>
                    </fo:block>
                  </fo:table-cell>
                </fo:table-row>
		
		<!-- When the apply-templates is executed by the XSLT processor
		     all matching child nodes (from the XML document are processed).
		     So, in our example, any role elements nested within a User
		     will be processed by the xsl:template below that matches on 
		     role -->

                <xsl:apply-templates/>
              </fo:table-body>
            </fo:table>
          </fo:block>
          <!-- END MAIN TABLE -->
        </fo:flow>
      <!-- END MAIN BODY -->
      </fo:page-sequence>
    </fo:root>
    </xsl:template>

    <!-- =================== -->
    <!-- child element: role -->
    <!-- =================== -->

    <!-- If there are multiple role elements nested within the User then
         a row per role end up in the PDF doc -->
    <xsl:template match="role">
      <fo:table-row>
        <fo:table-cell font-weight="bold" padding="2px" border="solid black 1px">
          <fo:block>
            Role name 
          </fo:block>
        </fo:table-cell>
        <fo:table-cell padding="2px" border="solid black 1px">
          <fo:block>
            <xsl:value-of select="roleName"/>
          </fo:block>
        </fo:table-cell>
      </fo:table-row>
    </xsl:template>
</xsl:stylesheet>
