Misc
- XSLT (Extensible Stylesheet Language
Transformation)
- Specifies how to convert a set of XML
files into another data
format (i.e. HTML)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
...
</xsl:stylesheet>
- When generating HTML or XML with an XSLT
stylesheet, the text
is fully normalized
- Occurrences of
< and & have to
be
converted to < and &
(respectively) or enclosed in a
CDATA section: <![CDATA[...]]>
- {$name} : Use a variable or parameter outside of an XSLT tag
<a href="{$url}">text</a>
- {@name} : Use an attribute outside of an XSLT tag
<a href="{@url}">text</a>
Functions
document
document(string)
- Access nodes in an external document
<xsl:value-of select="document('file.xml')/root-element/child-element[@attr-name=$myValue]"/>
text
text()
- Extract only the text value of the node (not the descendants)
<xsl:value-of select="text()"/>
Flow of control
Built-in rule
- The default rule
- When an element is reached that has no matching template
tag, or when apply-templates is called for the current element
- The text value of the current element is processed, and then the
children elements are processed, recursively
- Attributes are not processed
Defined rules
- When an element has a matching template, the built-in
template rule is not applied
- If the template includes a call to apply-templates for the
current element, then the
built-in rule is applied to the element
Terms
- Element: an XML tag
- Attribute: a name-value pair in an XML tag
- Node: an element or attribute (a single piece of data in the
document tree)
- XSLT element: an XSLT tag (
xsl:...)
- Rule: a template element (
xsl:template)
Misc
- The XML prolog is not required, but it's safer to use it, so that
the proper encoding can be specified; a version attribute is required
<?xml version="1.0" [encoding="..."]?>
- A namespace attribute is required in the root element, and a
version
attribute
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">...</xsl:stylesheet>
<xsl:output method="<xml,html,text>"
[omit-xml-declaration="<yes,no>"]
[indent="<yes,no>"]
[cdata-section-elements="..."]
/>