You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by do...@cocoon.apache.org on 2004/07/09 09:40:35 UTC

[Cocoon Wiki] Updated: BeginnerSimpleXSLT

   Date: 2004-07-09T00:40:35
   Editor: DavidCrossley <cr...@apache.org>
   Wiki: Cocoon Wiki
   Page: BeginnerSimpleXSLT
   URL: http://wiki.apache.org/cocoon/BeginnerSimpleXSLT

   remove junk attachment

Change Log:

------------------------------------------------------------------------------
@@ -4,28 +4,28 @@
 
 = Principles =
 First of all, you should see a little of how XML looks. So let's take a very short document
-{{{
-<article>
-  <title>BeginnerSimpleXSLT</title>
-  <author>FredericGlorieux</author>
-  <abstract>Dummy XML document</abstract>
-  <section>
-    <title>section 1</title>
-    <para>Some <bold>bold</bold> and <italic>italic</italic> text</para>
-  </section>
-</article>
+{{{
+<article>
+  <title>BeginnerSimpleXSLT</title>
+  <author>FredericGlorieux</author>
+  <abstract>Dummy XML document</abstract>
+  <section>
+    <title>section 1</title>
+    <para>Some <bold>bold</bold> and <italic>italic</italic> text</para>
+  </section>
+</article>
 }}}
 
 This doc is nicer than HTML, especially as I can change the Schema/DTD for my specific usage (<abstract/>, <author/>). Now, how do we take advantage of this? XSLT, of course.
 
 == Root ==
 This will be the root XSL document in which all snippets will now go.
-{{{
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-  <xsl:output method="xml" encoding="UTF-8"/>
-  <!-- here put your templates -->
-</xsl:stylesheet>
+{{{
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+  <xsl:output method="xml" encoding="UTF-8"/>
+  <!-- here put your templates -->
+</xsl:stylesheet>
 }}}
 
 
@@ -59,12 +59,12 @@
 
 === match, select, XPath ===
 
-{{{
-<!-- this template supposed to be in a xsl:stylesheet described upper --->
-<xsl:template match="/">
-<!-- here, we are at root of the xml input, before the first element -->
-  <xsl:copy-of select="."/>
-</xsl:template>
+{{{
+<!-- this template supposed to be in a xsl:stylesheet described upper --->
+<xsl:template match="/">
+<!-- here, we are at root of the xml input, before the first element -->
+  <xsl:copy-of select="."/>
+</xsl:template>
 }}}
 
 {{{<xsl:template match="/">}}}
@@ -82,25 +82,25 @@
 
 But don't forget what we really want. From the input given upper, imagine we want this short output, with no more content.
 
-{{{
-<short>
-  <title>BeginnerSimpleXSLT</title>
-  <author>FredericGlorieux</author>
-  <abstract>Dummy XML document</abstract>
-</short>
+{{{
+<short>
+  <title>BeginnerSimpleXSLT</title>
+  <author>FredericGlorieux</author>
+  <abstract>Dummy XML document</abstract>
+</short>
 }}}
 
 This template should do the job
 
-{{{
-<xsl:template match="/article">
-<!-- here, we are after the first element -->
-  <short>
-    <xsl:copy-of select="title"/>
-    <xsl:copy-of select="author"/>
-    <xsl:copy-of select="abstract"/>
-  </short>
-</xsl:template>
+{{{
+<xsl:template match="/article">
+<!-- here, we are after the first element -->
+  <short>
+    <xsl:copy-of select="title"/>
+    <xsl:copy-of select="author"/>
+    <xsl:copy-of select="abstract"/>
+  </short>
+</xsl:template>
 }}}
 
 Now, I'm matching XML input with an {{{<article/>}}} root element (happily, it's my input). This will change the current node inside the template for all new XPath expressions (ex: @select). Note also the <short/> element, which is not in the XSLT namespace (no xsl: prefix), so the engine will interpret it as output. And now point the three copy-of, working in the article context, so the @select are respectively catching and ouputting the {{{<title/>, <author/>, <abstract/>}}} nodes.
@@ -112,6 +112,4 @@
 = Resources =
 
 Links.
-[[BR]]
-[[BR]]
-'''Attachment:''' attachment:%26%2348148 [[BR]]
+