FlexDoc/XML - Samples - Alternative to XSLT

This sample demonstrates how FlexDoc/XML can be used as an alternative to a standard XSL Transformation.

  1. Sample Data
  2. Using XSLT
  3. FlexDoc/XML Alternative

1. Sample Data

The sample data are taken from the following XML document:

personal.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel SYSTEM "personal.dtd">
<personnel>
<person id="Big.Boss">
<name>
<family>Boss</family>
<given>Big</given>
</name>
<email>chief@foo.com</email>
<link subordinates="one.worker two.worker three.worker four.worker five.worker"/>
</person>
<person id="one.worker">
<name>
<family>Worker</family>
<given>One</given>
</name>
<email>one@foo.com</email>
<link manager="Big.Boss"/>
</person>
<person id="two.worker">
<name>
<family>Worker</family>
<given>Two</given>
</name>
<email>two@foo.com</email>
<link manager="Big.Boss"/>
</person>
<person id="three.worker">
<name>
<family>Worker</family>
<given>Three</given>
</name>
<email>three@foo.com</email>
<link manager="Big.Boss"/>
</person>
<person id="four.worker">
<name>
<family>Worker</family>
<given>Four</given>
</name>
<email>four@foo.com</email>
<link manager="Big.Boss"/>
</person>
<person id="five.worker">
<name>
<family>Worker</family>
<given>Five</given>
</name>
<email>five@foo.com</email>
<link manager="Big.Boss"/>
</person>
</personnel>

The XML's structure is described by this DTD-file:

personal.dtd

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

<!ELEMENT personnel (person)+>

<!ELEMENT person (name,email*,url*,link?)>
<!ATTLIST person id ID #REQUIRED>
<!ATTLIST person note CDATA #IMPLIED>
<!ATTLIST person contr (true|false) 'false'>
<!ATTLIST person salary CDATA #IMPLIED>

<!ELEMENT name ((family,given)|(given,family))>
<!ELEMENT family (#PCDATA)>
<!ELEMENT given (#PCDATA)>
<!ELEMENT email (#PCDATA)>

<!ELEMENT url EMPTY>
<!ATTLIST url href CDATA 'http://'>

<!ELEMENT link EMPTY>
<!ATTLIST link manager IDREF #IMPLIED>
<!ATTLIST link subordinates IDREFS #IMPLIED>

2. Using XSLT

Here's the XSLT-script defining the transformation:

personal.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<p>Personnel</p>
<xsl:element name="table">
<xsl:attribute name="border">2</xsl:attribute>
<tr>
<xsl:attribute name="color">#3333FF</xsl:attribute>
<xsl:attribute name="bgcolor">#FFCCCC</xsl:attribute>
<xsl:attribute name="align">center</xsl:attribute>
<td>
<font name="verdana" size="3">
<b>Name</b>
</font>
</td>
<td>
<font name="verdana" size="3">
<b>Email</b>
</font>
</td>
<td>
<font name="verdana" size="3">
<b>Link</b>
</font>
</td>
</tr>
<xsl:apply-templates/>
</xsl:element>
</html>
</xsl:template>
<xsl:template match="//person">
<xsl:element name="tr">
<xsl:attribute name="align">center</xsl:attribute>
<xsl:element name="td">
<font name="verdana" size="3">
<xsl:attribute name="width">120</xsl:attribute>
<i>
<xsl:value-of select="name/family/text()"/>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</i>
<xsl:value-of select="name/given/text()"/>
</font>
</xsl:element>
<xsl:element name="td">
<xsl:attribute name="width">120</xsl:attribute>
<font name="verdana" size="3">
<xsl:value-of select="email/text()"/>
</font>
</xsl:element>
<xsl:element name="td">
<font color="black" name="verdana" size="3">
<xsl:value-of select="./link/@subordinates"/>
<xsl:value-of select="./link/@manager"/>
</font>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

The HTML file produced with that XSLT-script is the following:

3. FlexDoc/XML Alternative

Here is how the corresponding FlexDoc template looks (click on the screenshot to see in full size):

Except of a few settings invisible on this screenshot, it is almost all needed to design as a replacement for the XSLT-script above.

To learn in every detail how to create and execute this template, please see Creating a Sample Template tutorial.

The XML Type definition prepared for this template consists of just three lines:
personal.name = Personal
personal.dtd.file = %FDH%/samples/personal/personal.dtd
personal.dtd.systemID = personal.dtd
This is the HTML document generated by the template (click on the image to view the real HTML):

And here is something XSL-processors normally do not at all – the RTF document generated with this template (click on the image to download the real RTF):