| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <head> |
| <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <title>XInclude Transformer</title> |
| <link href="http://purl.org/DC/elements/1.0/" rel="schema.DC"> |
| <meta content="in @doctitle@" name="DC.Subject"> |
| <meta content="Carsten Ziegeler" name="DC.Creator"> |
| <meta content="This document describes the XInclude transformer." name="DC.Description"> |
| </head> |
| <body> |
| |
| <h1>XInclude Transformer</h1> |
| |
| <p> |
| This transformer works according to the XInclude specification. |
| </p> |
| |
| <p> |
| For more information refer to the |
| <a class="external" href="http://www.w3.org/TR/xinclude">XInclude specification</a>. |
| </p> |
| |
| <ul> |
| |
| <li>Name : xinclude</li> |
| |
| <li>Class: org.apache.cocoon.transformation.XIncludeTransformer</li> |
| |
| <li>Cacheable: no.</li> |
| |
| </ul> |
| |
| <p> |
| You can include either simple text, or xml content. |
| Including xml content -- which is the default -- |
| gives you the option to define an xpointer in the href attribute. Some |
| quick xinclude examples should reveal the possibilities of xinclude. |
| </p> |
| |
| <ul> |
| |
| <li> |
| Include an xml content as-is: |
| <span class="codefrag"><xi:include href="include.xml"/></span> |
| |
| </li> |
| |
| <li> |
| Include an xml content but pick the strong element only: |
| <span class="codefrag"><xi:include href="include.xml#xpointer(/p/strong)"/></span> |
| |
| </li> |
| |
| <li> |
| Include text content: |
| <span class="codefrag"><xi:include parse="text" href="include.txt"/></span> |
| |
| </li> |
| |
| </ul> |
| |
| |
| <p> |
| A simple example using xinclude might help to use this transfomer |
| effectively: |
| </p> |
| |
| <p> |
| Add the XIncludetransfomer to the components in your sitemap.xmap |
| </p> |
| |
| <pre class="code"> |
| ... |
| <map:components> |
| ... |
| <map:transformers default="xslt"> |
| ... |
| <map:transformer name="xinclude" |
| src="org.apache.cocoon.transformation.XIncludeTransformer"/> |
| ... |
| </pre> |
| |
| |
| <p> |
| Next define in your pipeline to use the XIncludeTransformer |
| </p> |
| |
| <pre class="code"> |
| <map:match pattern="xinc/simple-xinc"> |
| <map:generate src="xinc/simple-xinc.xml"/> |
| <map:transform type="xinclude"/> |
| <map:transform src="stylesheets/page/simple-page2html.xsl"/> |
| <map:serialize/> |
| </map:match> |
| </pre> |
| |
| |
| <p> |
| In this example pipeline it assumed that simple-xinc.xml contains |
| the include element. As well as defining the include element, |
| it defines the namespace URI "http://www.w3.org/2001/XInclude". |
| This helps the XIncludeTransformer to find the include element to |
| get replaced by the included content. |
| The simple-xinc.xml may look like this: |
| </p> |
| |
| <pre class="code"> |
| <?xml version="1.0" encoding="UTF-8"?> |
| <page |
| xmlns:xi="http://www.w3.org/2001/XInclude"> |
| <title>Hello</title> |
| <content> |
| <para>This is my first Cocoon page!</para> |
| <xi:include href="include.xml"/> |
| </content> |
| </page> |
| </pre> |
| |
| |
| <p> |
| Next you should define the include.xml file which is included. |
| A simple include.xml might look like this: |
| </p> |
| |
| <pre class="code"> |
| <?xml version="1.0"?> |
| <p> |
| I am <strong>included</strong> by XIncludeTransformer. |
| I come from "include.xml". |
| </p> |
| </pre> |
| |
| |
| <p> |
| Now finally we have everything put together the xml content after the |
| XIncludeTransformer processing will look like this: |
| </p> |
| |
| <pre class="code"> |
| <?xml version="1.0" encoding="UTF-8"?> |
| <page |
| xmlns:xi="http://www.w3.org/2001/XInclude"> |
| <title>Hello</title> |
| <content> |
| <para>This is my first Cocoon page!</para> |
| <p> |
| I am <strong>included</strong> by XIncludeTransformer. |
| I come from "include.xml". |
| </p> |
| </content> |
| </page> |
| </pre> |
| |
| |
| </body> |
| </html> |