You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by fleur diana dragan <fl...@obscure.org> on 2000/09/16 03:39:45 UTC
xinclude example
Hi,
While playing around with Cocoon and the xinclude processor, I wrote
what I think is a better example for it, and I thought I'd share. I've
attached a patch file. I've never contributed stuff via patch file
before, and I'm not positive I've got it correct, so I've included the
commands I used to get it. It does seem to work properly when I apply
it.
[fleur@woodchuck ~/src]$ cd xml-cocoon-dev/samples/xinclude/
[fleur@woodchuck ~/src]$ diff -Naur xml-cocoon-pure/samples/xinclude xml-cocoon/samples/xinclude >> xinclude_patch
Hope someone finds this useful.
thanks,
fleur
--
Fleur [Diana] Dragan / fleur@obscure.org -- It's my name. Really.
===File ~/src/xinclude_patch================================
diff -Naur xml-cocoon-pure/samples/xinclude/index.xml xml-cocoon/samples/xinclude/index.xml
--- xml-cocoon-pure/samples/xinclude/index.xml Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/index.xml Fri Sep 15 20:59:53 2000
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="../index.xsl" type="text/xsl"?>
+<?cocoon-process type="xslt"?>
+
+<samples>
+ <group name="XInclude Example">
+ <sample name="A Poem" url="xinclude_poem.xml">
+ This is an example of xinclude (combined with xslt, so you get
+ some browser-renderable output). There are three xinclude
+ directives in it: a simple include parsed as text, a simple
+ include parsed as xml and a more complicated include using
+ xpointer parsed as xml. Plus the xpointer included stanza
+ itself has an xinclude in it, illustrating nested xinclude.
+ </sample>
+ </group>
+
+</samples>
diff -Naur xml-cocoon-pure/samples/xinclude/line1.txt xml-cocoon/samples/xinclude/line1.txt
--- xml-cocoon-pure/samples/xinclude/line1.txt Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/line1.txt Fri Sep 15 09:59:35 2000
@@ -0,0 +1 @@
+there was a little girl
diff -Naur xml-cocoon-pure/samples/xinclude/line2.xml xml-cocoon/samples/xinclude/line2.xml
--- xml-cocoon-pure/samples/xinclude/line2.xml Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/line2.xml Fri Sep 15 20:53:10 2000
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ This file is included via xinclude in the xinclude_poem.xml
+ document.
+ -->
+
+<line>who had a little curl</line>
diff -Naur xml-cocoon-pure/samples/xinclude/line6.txt xml-cocoon/samples/xinclude/line6.txt
--- xml-cocoon-pure/samples/xinclude/line6.txt Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/line6.txt Fri Sep 15 21:01:03 2000
@@ -0,0 +1 @@
+and when she was bad, she was horrid.
diff -Naur xml-cocoon-pure/samples/xinclude/poem.xml xml-cocoon/samples/xinclude/poem.xml
--- xml-cocoon-pure/samples/xinclude/poem.xml Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/poem.xml Fri Sep 15 21:01:50 2000
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="poem.xsl" type="text/xsl"?>
+<?cocoon-process type="xinclude"?>
+<?cocoon-process type="xslt"?>
+
+<!--
+ This file is provided to illustrate XInclude using XPointer.
+ The second stanza of this poem is included in xinclude_poem.xml.
+
+ This also works by itself as an xslt example, but that's
+ just for completeness.
+ -->
+
+<poem xmlns:xinclude="http://www.w3.org/1999/XML/xinclude" title="A Poem">
+
+ <stanza id="1">
+ <line>there was a little girl</line>
+ <line>who had a little curl</line>
+ <line>right in the middle of her forehead</line>
+ </stanza>
+
+ <stanza id="2">
+ <line>and when she was good</line>
+ <line>she was very very good</line>
+ <line><whatever xinclude:href="line6.txt" xinclude:parse="text" /></line>
+ </stanza>
+
+</poem>
diff -Naur xml-cocoon-pure/samples/xinclude/poem.xsl xml-cocoon/samples/xinclude/poem.xsl
--- xml-cocoon-pure/samples/xinclude/poem.xsl Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/poem.xsl Fri Sep 15 21:21:46 2000
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+ id="poem_style"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<!--
+ This file is provided purely to make the "poem.xml" file a
+ complete xslt example, which is not, in fact, the point of this
+ exercise.
+ -->
+
+ <xsl:template match="poem">
+ <html>
+ <head>
+ <title>
+ <xsl:value-of select="@title"/>
+ </title>
+ </head>
+ <body bgcolor="#ffffff">
+ <h1><xsl:value-of select="@title"/></h1>
+ <xsl:apply-templates select="stanza"/>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="stanza">
+ <p>
+ <xsl:apply-templates />
+ </p>
+ </xsl:template>
+
+ <xsl:template match="line">
+ <xsl:value-of select="." /><br></br>
+ </xsl:template>
+
+</xsl:stylesheet>
diff -Naur xml-cocoon-pure/samples/xinclude/xinclude_poem.xml xml-cocoon/samples/xinclude/xinclude_poem.xml
--- xml-cocoon-pure/samples/xinclude/xinclude_poem.xml Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/xinclude_poem.xml Fri Sep 15 21:13:51 2000
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="xinclude_poem.xsl" type="text/xsl"?>
+<?cocoon-process type="xinclude"?>
+<?cocoon-process type="xslt"?>
+
+<!--
+ This file illustrates the xinclude filter, including
+ parse="text", parse="xml" and a href containing an XPointer
+ expression. The bit included by the xpointer include itself
+ contains an include.
+
+ This document is also processed a second time (as evidenced
+ by the cocoon PIs above) using xslt to produce nice output,
+ which isn't strictly necessary for the example, but it's nice
+ to get something to see in your browser when you hit xinclude_poem.xml.
+ -->
+
+<poem xmlns:xinclude="http://www.w3.org/1999/XML/xinclude" title="A Poem">
+
+ <stanza>
+ <line><whatever xinclude:href="line1.txt" xinclude:parse="text" /></line>
+ <whatever xinclude:href="line2.xml" xinclude:parse="xml" />
+ <line>right in the middle of her forehead</line>
+ </stanza>
+
+ <include xinclude:parse="xml"
+ xinclude:href="poem.xml#xpointer(//stanza[@id='2'])" />
+
+</poem>
diff -Naur xml-cocoon-pure/samples/xinclude/xinclude_poem.xsl xml-cocoon/samples/xinclude/xinclude_poem.xsl
--- xml-cocoon-pure/samples/xinclude/xinclude_poem.xsl Wed Dec 31 19:00:00 1969
+++ xml-cocoon/samples/xinclude/xinclude_poem.xsl Fri Sep 15 21:19:24 2000
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+
+<!--
+ This file is the stylesheet for the xinclude_poem.xml example
+ so that something browser-renderable comes out.
+ -->
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+ <xsl:template match="poem">
+ <html>
+ <head>
+ <title>
+ <xsl:value-of select="@title"/>
+ </title>
+ </head>
+ <body bgcolor="#ffffff">
+ <h1><xsl:value-of select="@title"/></h1>
+ <xsl:apply-templates select="stanza"/>
+ </body>
+ </html>
+ </xsl:template>
+
+ <xsl:template match="stanza">
+ <p>
+ <xsl:apply-templates />
+ </p>
+ </xsl:template>
+
+ <xsl:template match="line">
+ <xsl:value-of select="." /><br></br>
+ </xsl:template>
+
+</xsl:stylesheet>
============================================================
Re: xinclude example
Posted by Donald Ball <ba...@webslingerZ.com>.
On 15 Sep 2000, fleur diana dragan wrote:
> Hi,
>
> While playing around with Cocoon and the xinclude processor, I wrote
> what I think is a better example for it, and I thought I'd share. I've
> attached a patch file. I've never contributed stuff via patch file
> before, and I'm not positive I've got it correct, so I've included the
> commands I used to get it. It does seem to work properly when I apply
> it.
>
> [fleur@woodchuck ~/src]$ cd xml-cocoon-dev/samples/xinclude/
> [fleur@woodchuck ~/src]$ diff -Naur xml-cocoon-pure/samples/xinclude xml-cocoon/samples/xinclude >> xinclude_patch
>
> Hope someone finds this useful.
i added it to the samples directory, thanks lots!
- donald