XSLT 2.0

The xml summer school is over. i attended talks by jenni tennison and michael kay on xslt 2.0. herewith my rough notes. hopefully they prove useful for someone, even in their rough form.
jenni tennison on xslt 2.0

grouping in sequence: paging in xslt
<xsl:for-each select=”paper” group-starting-with=”paper[position() mod10= 1]”>
<xsl:result-document href=”papers{position()}.html”>
result-element for writing multiple documents
it is possible to access these documents via the href URI (say, from another stylesheet)
stored relative to “base output URI”
implications: no more muenchian grouping!
easier to create indexes, summaries, pagination
xsl functions can be replacements for named templates.
functions for atomic values, named templates for mixed content
xslt 2.0 supports xml 1.1 namespace undeclarations
character substitution to create non-wellformed output. map <%@ mapping to unicode
private area:
@ page language =
unfortunately, all this won’t matter so much since microsoft will not support xslt 2.0
what is xsl:sequence??
squences in xpath 2.0
everything is a sequence, like nodeset() but ordered
implication: much less need for recursive templates, less need for temporary elements
xslt 2.0 doesn’t need the result set extension anymore, results are temporary trees
this means complex transformations can be broken up into multiple steps
create a text node from a sequence:
<xsl:value-of select=”author/surname” separator=”, “/> thomson, tobin
xsl:unparsed-text() similar to document(), but for text nodes.. interesting for includes
parameter changes:
tunnel params: set param high up in the call stack, us it low down, without passing it through explicitly
required param: error if value isnt provided
xsl:next-match calls template that would have matched if the current wouldn’t have been there
match=”a[@id=

xsl:next-match
match=”a”
…¨
using schemas / types may make things easier, not using them may make things harder.

michael kay on schema support in xslt 2.0

much more robust code. put validation into xslt
sequence of strings: multiple lines of text, is not an xml document
for-each select=$lines
“find it useful to always declare types” for debugging
performance?
4 different grouping functions:
group-by
group-adjacent
group-starting-with
group-ending-with
eq was introduced as a simplified = for performance reasons (it only matches once)
, in select? -> , concatenates sequences. is not an OR
select=”current-group() except .” selects the current group except the context node.
except is new in xpath 2.0
this serves as terminating condition for recursive templates too 🙂
<xsl:result-document validation=”strict”> produces the output
concept of output-driven stylesheet versus input-driven. “how should the output look?” -> pull. “how does the input look?” -> push
new: union within xpath: /book/chapter|section/p
–> xsl validation points straight at the source of validation errors, no guesswork which
template produced the wrong output
-> but, when you build up, you want bigger picture. sometimes, turn validation off
input and output schemas
tip: use xsl:key for inverse relationships
“xsl functions are quite object oriented. they operate on the data structure”
if (data($date) instance of StandardDate)
-> convert to ISO. this allows to check for types. allows for fallback!!
standard date would be something like 200-05-03
there could also be: 200? may ??
or even “in the year the jakal ruled”
-> all are valid, but fallback

Leave a comment