用XSLT实现导航面包屑-Breadcrumb

本示例实现了显示当前所在位置的功能。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<!-- start writing XSLT -->
<!--<a href='umbraco.library:NiceUrl($currentPage/@id)'><xsl:value-of select="$currentPage/@nodeName"/></a>-->
<xsl:for-each select="$currentPage/ancestor-or-self::node">
    <xsl:choose>
        <xsl:when test="$currentPage/@id=current()/@id">
            <xsl:value-of select="@nodeName" />
        </xsl:when>
        <xsl:otherwise>
        <a href="{umbraco.library:NiceUrl(./@id)}">
            <xsl:attribute name="title"><xsl:value-of select="./@nodeName" /></xsl:attribute>
            <xsl:value-of select="./@nodeName" />
        </a>&gt;
        </xsl:otherwise>
    </xsl:choose>
</xsl:for-each>

</xsl:template>

 

以上是本站原创,感兴趣的亦可访问以下地址,看看umbraco.org的实现方式。

http://umbraco.org/xslt/Breadcrumb.xslt