Search code examples
xmlxsltxsl-foapache-fop

Generate a pdf to document a database in XSLT


I have a XML related to a database and have to generate a PDF to document the database. I am using FOP to convert XSLT to PDF.

XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sql-catalog xmlns="http://www.abc.com">
    <schemas>
        <schema name="abc>
            <tables>
                <table name="tab123" degree="1" type="TABLE" rows="144">
                    <columns>
                        <column name="asd" nullable="true" order="1" sqlType="CHARACTER VARYING" sqlLength="255" fixedLength="2"/>
                        <column name="pqr" nullable="true" order="2" sqlType="CHARACTER VARYING" sqlLength="255" fixedLength="2"/>
                    </columns>
                    <constraints/>
                    <datafiles>
                        <datafile href="abc.txt" checksum="6ba3a161d5" size="12354" format="FIXED" valid="true" recordTerminator="&#xD;&#xA;" checksumtype="MD5" rows="905"/>
                    </datafiles>
                </table>
            </tables>
        </schema>
    </schemas>
</sql-catalog>

I have to display the table name, number of columns and column name. I have written the following in XSLT.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ora="http://www.oracle.com/XSL/Transform/java/" xmlns:xdofo="http://xmlns.oracle.com/oxp/fo/extensions" xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions" xmlns:xdoxliff="urn:oasis:names:tc:xliff:document:1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:cat="http://www.abc.com">
    <xsl:output method="xml" encoding="ISO-8859-1"/>
    <xsl:template match="cat:sql-catalog">
    <fo:root>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="A4" page-height="297mm" page-width="210mm" margin-left="2cm" margin-right="2cm" margin-top="2.0cm" margin-bottom="1.0cm">
            <fo:region-body/>
            <fo:region-after extent="1cm"/>
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="A4">
           <fo:static-content flow-name="xsl-region-after" font-size="8pt">
               <fo:block text-align="right">
                    <fo:page-number/>
               </fo:block>
           </fo:static-content>

      <fo:flow flow-name="xsl-region-body">

            <fo:block font-weight="bold" font-size="8pt" space-after="0.5cm">
                <xsl:value-of select="cat:schemas/schema/tables/table/@name" />
            </fo:block>

        </fo:flow>
    </fo:page-sequence>
    </fo:root>
  </xsl:template>
</xsl:stylesheet>

In the code I have tried to display the name of the table which is in the attribute, but it doesn't seem to work. Can any one please tell me where am I going wrong here? And also how to count the number of columns in the table.


Solution

  • You need to prefix every element name in the XPath expression with the cat namespace. Try:

    <xsl:value-of select="cat:schemas/cat:schema/cat:tables/cat:table/@name"/>