Delphi and XML - XSL example
(Page 2 of 4 )
As you can see, each tag describes its contents very clearly. For example, the <title> tag describes the title, the description tag shows the description, and so on. Below is an example of an XSL style sheet:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="iso-8859-1" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*">
<table border="1" width="600" align="center">
<tr><td valign="top" align="center" class="title" bgcolor="silver" >
<a>
<xsl:attribute name="href">
<xsl:value-of select="*[local-name()='channel']/*[local-name()='link']"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>top</xsl:text>
</xsl:attribute>
<xsl:value-of select="*[local-name()='channel']/*[local-name()='title']" disable-output-escaping="yes"/>
</a>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:value-of select="*[local-name()='channel']/*[local-name()='lastBuildDate']"/>
</td></tr><tr><td valign="top" bgcolor="ghostwhite" class="headlines" >
<ul>
<xsl:for-each select="//*[local-name()='item']">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="*[local-name()='link']"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>top</xsl:text>
</xsl:attribute>
<xsl:value-of select="*[local-name()='title']" disable-output-escaping="yes"/>
</a>
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
<xsl:value-of select="*[local-name()='description']" disable-output-escaping="yes"/>
</li>
</xsl:for-each>
</ul>
</td></tr>
</table>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
XML has a few disadvantages as well. The biggest disadvantage is that, without a formal description, a document is worth little. If you want to exchange documents with another company, for example, you will have to agree on every single point, starting from what each tag means; you will also have to agree on the semantic meaning of the content.
Another disadvantage is that XML documents are a great deal larger than most text files. On top of that, the repeated opening and closing tags use a lot of space. On the other hand. XML compresses well.
Now you have some idea of what the Extensible Markup Language is all about. Let’s take a look at the syntax.
Next: XML Syntax >>
More Delphi-Kylix Articles
More By David Web