The XML Component Set"
From Documentation
(Created page with '{{ZKDevelopersGuidePageHeader}} == The XML Component Set == In addition to generating XML tags directly to the output, the XML component set provides a few components to simplif…') |
m (correct highlight (via JWB)) |
||
Line 5: | Line 5: | ||
=== The XML Transformer === | === The XML Transformer === | ||
− | To translate a XML document to another, you can use the < | + | To translate a XML document to another, you can use the <code>transformer</code> component as follows. |
<source lang="xml" > | <source lang="xml" > | ||
Line 20: | Line 20: | ||
where transformer is a component of the XML component set, so we have to specify the namespace. Otherwise, the Native namespace is assumed. | where transformer is a component of the XML component set, so we have to specify the namespace. Otherwise, the Native namespace is assumed. | ||
− | Then, let us assume the content of < | + | Then, let us assume the content of <code>book.xsl</code> is as follows. |
<source lang="xml" > | <source lang="xml" > |
Latest revision as of 10:41, 19 January 2022
This documentation is for an older version of ZK. For the latest one, please click here.
The XML Component Set
In addition to generating XML tags directly to the output, the XML component set provides a few components to simplify sophisticated tasks, such as XSLT.
The XML Transformer
To translate a XML document to another, you can use the transformer
component as follows.
<?page contentType="text/html;charset=UTF-8"?>
<x:transformer xsl="book.xsl" xmlns:x="http://www.zkoss.org/2007/xml">
<book>
<title>ZK - Ajax without the JavaScript Framework</title>
<for-who>Web application designers and programmers who wish to implement rich Ajax web applications in the simplest way.</for-who>
<author>Henri Chen and Robbie Cheng</author>
</book>
</x:transformer>
where transformer is a component of the XML component set, so we have to specify the namespace. Otherwise, the Native namespace is assumed.
Then, let us assume the content of book.xsl
is as follows.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Book Info</title>
</head>
<body>
<h1>Book Info</h1>
<xsl:apply-templates select="book"/>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<dl>
<dt>Title:</dt>
<dd><xsl:value-of select="title"/></dd>
<dt>Who is this book for:</dt>
<dd><xsl:value-of select="for-who"/></dd>
<dt>Authors</dt>
<dd><xsl:value-of select="author"/></dd>
</dl>
</xsl:template>
</xsl:stylesheet>
Then, the generated XML output will be XHTML as follows.
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Book Info</title>
</head>
<body>
<h1>Book Info</h1>
<dl>
<dt>Title:</dt>
<dd> ZK - Ajax without the JavaScript Framework</dd>
<dt>Who is this book for:</dt>
<dd> Web application designers and programmers who wish to implement
rich Ajax web applications in the simplest way.</dd>
<dt>Authors</dt>
<dd> Henri Chen and Robbie Cheng</dd>
</dl>
</body>
</html>