/ Published in: XSLT
a perfect tree representation of a XML structure (with i, l and t and empty node images)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet exclude-result-prefixes="xsl xsi html xsd" version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output encoding="UTF-8" indent="no" method="xml" omit-xml-declaration="yes"/> <xsl:strip-space elements="*"/> <xsl:param name="id" /> <xsl:template match="/"> <xsl:apply-templates select="//navigation[@id=$id]" /> </xsl:template> <xsl:template match="navigation"> <table class="table" id="links"> <thead> <tr> </tr> </thead> <tbody> <tr class="level0"> </tr> <xsl:apply-templates select="links" /> </tbody> </table> </xsl:template> <xsl:template match="link"> <xsl:variable name="chain" select="ancestor-or-self::link" /> <tr class="level{count($chain)}"> <td> <xsl:apply-templates select="$chain" mode="tracks"> <xsl:with-param name="context" select="." /> </xsl:apply-templates> </td> <td> <xsl:choose> <xsl:when test="string-length(title)>0"> <xsl:value-of select="substring(title,0,50)" /> </xsl:when> <xsl:otherwise> </xsl:otherwise> </xsl:choose> </td> <td> <div class="btn-group"> <xsl:choose> <xsl:when test="active='yes'"> </xsl:when> <xsl:when test="active='no'"> </xsl:when> </xsl:choose> <a href="#"> <xsl:attribute name="class">btn btn-mini <xsl:choose> <xsl:when test="position()=1"> disabled</xsl:when> </xsl:choose> </xsl:attribute> </a> <a href="#"> <xsl:attribute name="class">btn btn-mini <xsl:choose> <xsl:when test="position()=count($chain)"> disabled</xsl:when> </xsl:choose> </xsl:attribute> </a> </div> </td> </tr> <xsl:apply-templates select="links" /> </xsl:template> <xsl:template match="link" mode="tracks"> <xsl:param name="context" /> <xsl:variable name="isSame" select="generate-id(.) = generate-id($context)" /> <xsl:variable name="pos" select="count(preceding-sibling::link)" /> <xsl:variable name="isLast" select="not(following-sibling::link)" /> <xsl:variable name="type"> <xsl:choose> <xsl:when test="$isSame"> <xsl:if test="(following::link or links/link) and not($isLast)">t</xsl:if> <xsl:if test="$isLast">l</xsl:if> </xsl:when> <xsl:when test="$isLast and links/link">e</xsl:when> <xsl:when test="following::link and links/link">i</xsl:when> <xsl:when test="not(following::link)">e</xsl:when> </xsl:choose> </xsl:variable> <xsl:call-template name="node-type"> <xsl:with-param name="type" select="$type" /> </xsl:call-template> </xsl:template> <xsl:template name="node-type"> <xsl:param name="type" select="'t'" /> <img class="textmiddle" src="/images/backend/{$type}-node.png" /> </xsl:template> </xsl:stylesheet>