This stylesheet has been deprecated in favour of the links to unordered lists stylesheet.
Version 1.1 of this stylesheet was released to provide a bridge between this and the newer stylesheet for people who may be including previous versions in their XSL documents. It is no longer being actively developed.
This stylesheet defines two templates named ListAllRels
and ListOneRel
which will create one, or more, unordered lists based on the <link>
elements in the source document.
List items are grouped according to the rel
attribute. Elements whose rel
attribute is 'stylesheet' are explictly excluded.
The current version of the rels to unordered lists stylesheet is 1.1.
released December 14, 2002
# file:///path/to/your-stylesheet.xsl <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://www.w3.org/XML/1998/namespace" xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="h" version="1.0"> <!-- doctype stuff removed for the sake of brevity --> <xsl:output method="xml"/> <xsl:include href = "rels-to-unordered-lists.xsl" /> <xsl:template match="/"> <html> <xsl:attribute name = "x:lang"> <xsl:value-of select = "/h:html/@x:lang" /> </xsl:attribute> <!-- note that this will probably add a 'profile=""' attribute to your head element. don't worry, it's actually part of the spec, not that I've ever seen anyone use it... --> <xsl:copy-of select = "/h:html/h:head" /> <body> <xsl:for-each select="/h:html/h:body/@*"> <xsl:attribute name="{name()}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:for-each> <xsl:copy-of select = "/h:html/h:body/child::node()" /> <!-- this template is defined in the rels-to-unordered-lists stylesheet imported above --> <xsl:call-template name = "ListAllRels" /> </body> </html> </xsl:template> </xsl:stylesheet>
xsltproc \ -o /path/to/xhtml-file.html \ /path/to/your-stylesheet.xsl /path/to/xhtml-file.xml
If you're not wild about unordered lists you can redefine the ListOneRel
template in your stylesheet.
This is the template called by the ListAllRels
template for each disctinct link/@rel
attribute.
This is an example of how to modify the template to create a "horizontal" navigation menu that is suitable for text browsers but than can also be rendered or positioned in a CSS-enabled browser.
# prints a menu in the form of # [title|title][title] <xsl:template name = "ListOneRel"> <!-- this is a string containing the value of the @rel attribute, not a node --> <xsl:param name = "rel" /> <span> <xsl:attribute name = "class"> rel-link-<xsl:value-of select = "$rel" /> </xsl:attribute> [<xsl:for-each select = "/h:html/h:head/h:link[@rel = $rel]"> <span> <xsl:attribute name = "class"> rel-item </xsl:attribute> <a> <xsl:attribute name = "href"> <xsl:value-of select = "@href" /> </xsl:attribute> <xsl:attribute name = "title"> <xsl:value-of select = "@title" /> </xsl:attribute> <xsl:value-of select = "@title" /> </a> <xsl:variable name = "count" value-of = "count(/h:html/h:head/h:link[@rel = $rel])" /> <xsl:if test = "position() < $count">|</xsl:if> </span> </xsl:for-each>] </span> </xsl:template>
Copyright © 2002 Aaron Straup Cope. All Rights Reserved.
Permission to use, copy, modify and distribute this stylesheet and its acompanying documentation for any purpose and without fee is hereby granted in perpetuity, provided that the above copyright notice and this paragraph appear in all copies. The copyright holders make no representation about the suitability of the stylesheet for any purpose.
It is provided "as is" without expressed or implied warranty.