Page: http://wiki.cocoondev.org/Wiki.jsp?page=BeginnerSimpleXSLT , version: 2
on Sun May 18 20:30:46 2003 by 212.110.252.9
- I begin the page, in hope that some others will fill the holes (and correct
my english).
? ^ -----
^
+ I am beginning this page, in the hope that others will fill in the holes (and
correct my English).
? +++ ++++ ^^ ++++ +++
^
- Before, you should know a bit of what XML looks like. So let's take a very
short document
? ^^ ^^^ ^^^^ ^ --- -----
+ First of all, you should see a little of how XML looks. So let's take a very
short document
? ^^^^^^^ ^^^^ ^^^ ^ +++ ++
- This doc is nicer than HTML, especially because I can change the Schema/DTD
for my specific usage (<abstract/>, <author/>). Now, how to take advantage of
this? XSLT, of course.
? --- - -
^
+ 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.
?
^ +++
- {{<?xml version="1.0" encoding="UTF-8"?>}} First declaration that all xml
document should have.
? ^ ^^^
+ {{<?xml version="1.0" encoding="UTF-8"?>}} This is the first declaration that
all XML documents should have.
? ^^^^^^^^^^^^^
^^^ +
- Note the encoding precision, UTF-8 is default for XML.
? ^
+ Note the encoding precision: UTF-8 is default for XML.
? ^
+ Languages other than English could have may need a different encoding. For an
XSLT, leave it as UTF-8: your XML editor should know it.
- But languages other than english could have some surprise in a
- browser. For an XSL, let it as UTF-8, your XML editor should know it.
- Root element whith a namespace declaration (XML-spec).
? -
+ Root element with a namespace declaration (XML-spec).
- by xsl:* is mapped as the namespace-uri
"http://www.w3.org/1999/XSL/Transform".
? ^^ ^^
+ with xsl:* are mapped as the namespace-uri
"http://www.w3.org/1999/XSL/Transform".
? ^^^^ ^^^
- This is the only string identifying your tags as xslt instructions to process.
? ^^^^
+ This is the only string identifying your tags as XSLT instructions to process.
? ^^^^
- That means, you can also say
? ^^ -
+ This means you can also say
? ^^
- Could be useful when an xsl should output an xsl.
? ^ ^^^ ^^^
+ This could be useful when an XSLT should output another XSLT.
? ^^^^^^ ^^^^ +++++ ^^^^
- But before that, stay classic, it will be easier for copy/paste (by the way,
keep also the @version attribute).
+ However, for now let's keep it simple: it will be easier for copy/paste. (By
the way, also keep the @version attribute).
- All xsl:* will now be instructions to transform from an input to an output.
+ All xsl:* elements will now be instructions to transform from an input to an
output.
? +++++++++
- This is the reason of @method attribute.
? ^
+ This is the reason for @method attribute.
? + ^
- Note @encoding, one more time, let UTF-8 for xml usages, iso-8859-1 could be
useful if
? ^ - ^^^ ^^^
+ Note @encoding, one more time, use UTF-8 for XML usages, ISO-8859-1 could be
useful if
? ^^ ^^^ ^^^
- strange browser display.
+ you have a strange browser display.
? +++++++++++
- If I put some nice tags in my XML documents, it's probably to use them.
Example, I want to extract title|author|abstract of my articles to have a short
version. So let's write my first template to __pull__ what I need in the source
to output it.
? ^^ - ^
+ As I've put some nice tags in my XML document, it's probably best to use
them. For example, I want to extract title|author|abstract of my articles to
have a short version. So let's write my first template to __pull__ what I need
in the source to output it.
? ^^ +++ +++++
^^^^^
- The xslt engine is a kind of filter, processing an xml input,
? ^^^^ ^^^
+ The XSLT engine is a kind of filter, processing an XML input,
? ^^^^ ^^^
- with the stylesheet instructions. Imagine a complex search/replace, except
it's not working
?
^^ - ^
+ with the stylesheet instructions. Imagine a complex search/replace, except
instead of working
?
++ ^^^ ^
- on flat text, but on a tree of elements.
? - ^^
+ on flat text it's working on a tree of elements.
? ^ ++++++++++
- At first, the engine search for a template matching the root.
? ^^^
+ At first, the engine searching for a template matches the root.
? +++ ^^
- Thats what is provide here, in the @match, with the "/" value.
+ That's what is provided here, in the @match, with the "/" value.
? + +
- Unix users will fastly understand the syntax.
? ^^^^ ^
+ Unix users will quickly understand this syntax.
? ^^^^^ ^^
- Now, the current node will be the root of the xml input (like after a "change
directory").
? ^^^
+ Now, the current node will be the root of the XML input (like after a "change
directory").
? ^^^
- In fact, this very complex template is doing: __nothing__. Output should be
quite exactly the input in XML understanding, except encoding or some other
properties specified in the xsl:output instruction (only important for text
instance of an XML object). Not so unuseful...
?
^^^ - ^^^ -------
--
+ In fact, this very complex template is doing: __nothing__. Output should be
almost exactly the same as the input in XML terms, except the encoding or some
other properties specified in the xsl:output instruction (only important for
text instances of an XML object). Not so useful...
?
^^^^^ ++++++++++++ ^ + ++++
+
- It's also a fast way to debug XSL, to say "Where am I?", "What's in?". The
instruction ''copy-of'' output the nodes selected by the expression in @select,
here: ".". The dot express current node. It's another important character of
expressions, called XPath syntax.
+ It's also a fast way to debug XSL, to say "Where am I?", "What's in?". The
instruction ''copy-of'' outputs the nodes selected by the expression in
@select, here: ".". The dot expresses the current node. It's another important
characteristic of expressions, called XPath syntax.
?
+
++++++
+++++
- But don't forget what we want. From the input given upper, imagine we want
this short output, with no more content.
+ But don't forget what we really want. From the input given upper, imagine we
want this short output, with no more content.
? +++++++
- 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 expression (ex: @select). Note alse the <short/> element, which is
not in XSLT namespace (no xsl: prefix), so the engine will understand it as an
output. And now point the three copy-of, working in the article context, so the
@select are respectivly catching and ouputing the {{<title/>, <author/>,
<abstract/>}} nodes.
?
^ ^
^
^ ^ ^ --- ---
+ 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.
?
^ ^
+ ^
++++ ^ ^ ^^^
+ +
- Pocess for an html output.
+ Process for an html output.
? +