Transformer"

From Documentation
m ((via JWB))
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
=Employment/Purpose=
 
=Employment/Purpose=
  
<javadoc>org.zkoss.zml.Transformer</javadoc> is used to translate a XML document to another with a [[http://en.wikipedia.org/wiki/XSLT|XSTL]] template.
+
<javadoc>org.zkoss.zml.Transformer</javadoc> is used to translate a XML document to another with a [http://en.wikipedia.org/wiki/XSLT XSTL] template.
  
 
<source lang="xml" >
 
<source lang="xml" >
 
  <?page contentType="text/html;charset=UTF-8"?>
 
  <?page contentType="text/html;charset=UTF-8"?>
  <x:transformer xsl="book.xsl" xmlns:x="http://www.zkoss.org/2007/xml">
+
  <x:transformer xsl="book.xsl" xmlns:x="xml">
 
     <book>
 
     <book>
 
         <title>ZK - Ajax without the JavaScript Framework</title>
 
         <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>
+
         <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>
 
         <author>Henri Chen and Robbie Cheng</author>
 
     </book>
 
     </book>
Line 19: Line 20:
 
</source>
 
</source>
  
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: <code>xml</code>. Otherwise, the [[ZUML Reference/ZUML/Namespaces/Native|native namespace]] is assumed, and the element is generated directly.
  
Then, let us assume the content of <tt>book.xsl</tt> is as follows.
+
Then, let us assume the content of <code>book.xsl</code> is as follows.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 64: Line 65:
 
<dd> ZK - Ajax without the JavaScript Framework</dd>
 
<dd> ZK - Ajax without the JavaScript Framework</dd>
 
<dt>Who is this book for:</dt>
 
<dt>Who is this book for:</dt>
<dd> Web application designers and programmers who wish to implement
+
<dd>Web application designers and programmers who wish to implement
 
rich Ajax web applications in the simplest way.</dd>
 
rich Ajax web applications in the simplest way.</dd>
 
<dt>Authors</dt>
 
<dt>Authors</dt>
Line 75: Line 76:
 
=Version History=
 
=Version History=
 
{{LastUpdated}}
 
{{LastUpdated}}
{| border='1px' | width="100%"
+
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-

Latest revision as of 14:09, 12 January 2022

Transformer

Employment/Purpose

Transformer is used to translate a XML document to another with a XSTL template.

 <?page contentType="text/html;charset=UTF-8"?>
 <x:transformer xsl="book.xsl" xmlns:x="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: xml. Otherwise, the native namespace is assumed, and the element is generated directly.

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>

Version History

Last Update : 2022/01/12


Version Date Content
     



Last Update : 2022/01/12

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.