[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
Many of the new features of XSLT 2.0 have their roots in XPath 2.0 and the underlying new data model of sequences. But some features of XSLT 2.0 really are part of the language itself, such as support for user-defined functions, and the ability to group items and then iterate over these groups. In addition, XSLT now can be used as a typed programming language, which consumes and produces typed trees instead of just well-formed XML trees.
<xsl:function name="myns:format-date"> <xsl:param name="date"/> <xsl:value-of select="if ( $date castable as xs:date ) then format-date(xs:date($date), '[MNn] [D], [Y]') else if ( $date castable as xs:gYearMonth ) then format-date(xs:date(concat($date, '-01')), '[MNn] [Y]') else $date"/> </xsl:function>
<body> <div class="navigation"> <a href="{ if ( position() ne 1 ) then preceding-sibling::reference[1]/@name else following-sibling::reference[last()]/@name }.html">Previous</a> | <a href="../reference-list.html">Index</a> | <a href="{ if ( position() ne last() ) then following-sibling::reference[1]/@name else preceding-sibling::reference[last()]/@name }.html">Next</a> </div> <h2><xsl:value-of select="title"/></h2> <xsl:apply-templates select="names[@type='author']/*"/> <h4><a href="../reference-list.html#year{substring(date/@value, 1, 4)}"><xsl:value-of select="myns:format-date(date/@value)"/></a></h4> <xsl:if test="abstract"> <div class="abstract"><xsl:copy-of select="abstract/richtext/*"/></div> </xsl:if> </body>
contact[not(surname = preceding-sibling::contact/surname)]
<records> <contact id="0001"> <forename>John</forename> <surname>Smith</surname> </contact> <contact id="0002"> <forename>Amy</forename> <surname>Jones</surname> </contact> <contact id="0003"> <forename>Jimmy</forename> <surname>Jones</surname> </contact>
<xsl:key name="contacts-by-surname" match="contact" use="surname"/> <xsl:template match="records"> <ul> <xsl:for-each select="contact[count(. | key('contacts-by-surname', surname)[1]) = 1]"> <xsl:sort select="surname"/> <li><xsl:value-of select="surname"/> <ul> <xsl:for-each select="key('contacts-by-surname', surname)"> <xsl:sort select="forename"/> <li><xsl:value-of select="forename"/></li> </xsl:for-each> </ul> </li> </xsl:for-each> </ul> </xsl:template>
<xsl:result-document method="xhtml" href="reference-list.html"> <html> <head> <title>Reference List</title> <link rel="stylesheet" type="text/css" href="reference.css"/> </head> <body> <h2>Reference List</h2> <xsl:for-each-group select="//reference" group-by="substring(date/@value, 1, 4)"> <xsl:sort select="current-grouping-key()"/> <h5 id="year{current-grouping-key()}"><xsl:value-of select="current-grouping-key()"/></h5> <ul> <xsl:for-each select="current-group()"> <xsl:sort select="title"/> <li><a href="reference/{@name}.html"><xsl:value-of select="title"/></a></li> </xsl:for-each> </ul> </xsl:for-each-group> </body> </html> </xsl:result-document>
xs:date( if ( $i castable as xs:date ) then $i else '2000-01-01' )