...

View Full Version : XSL Stylesheet Help



ynotlim
02-26-2009, 02:51 AM
Hello,

I'm creating a breadcrumb tool.

Currently I'm getting:
Name 1 > Name 2 > Name 3
but I want to get
Name 1 > Name 2 > Name 3 > Current Page

Thanks for the help!

Tony


<system-index-block current-time="1235615500057" name="breadcrumbs" type="folder">
<system-folder id="ROOT">
<name>/</name>

<display-name>/</display-name>

<path>//</path>

<system-folder id="023ad30e80c8a8b60127f2bb75bb4341">
<name>Name 1</name>

<path>/Level1</path>

<system-folder id="78726c5a80c8a8b600a10ea258fc198e">
<name>Name 2</name>

<path>/Level1/Level2</path>

<system-folder current="true" id="6c68278280c8a8b6001b9c3fc643c32d">
<name>Name 3</name>

<path>/Level1/Level2/Level3</path>

<system-page current="true" id="6c6833bc80c8a8b6001b9c3fe310f944">
<name>Current Name</name>

<path>/Level1/Level2/Level3/index</path>
</system-page>
</system-folder>
</system-folder>
</system-folder>
</system-folder>
</system-index-block>


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>

<xsl:template match="system-index-block">
<ul>
<xsl:apply-templates select="descendant::system-folder[descendant::system-page[@current = 'true']][count(ancestor::system-folder) > 0]"/>
</ul>
</xsl:template>

<xsl:template match="system-folder">

<li>
<xsl:if test="position() = 1">
<xsl:attribute name="class">first</xsl:attribute>
</xsl:if>
<a>
<xsl:attribute name="href">
<xsl:value-of select="system-page[name = 'index']/path"/>
</xsl:attribute>

<xsl:call-template name="get-name"/>
</a>
</li>
</xsl:template>


<xsl:template name="get-name">
<xsl:choose>
<xsl:when test="display-name">
<xsl:value-of select="display-name"/>

</xsl:when>
<xsl:when test="title">
<xsl:value-of select="title"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>

shyam
02-26-2009, 06:48 PM
you wrote this descendant::system-folder[descendant::system-page[@current = 'true']][count(ancestor::system-folder) > 0] wicked xpath and have trouble fixing that? :rolleyes: i'm having trouble believing that :rolleyes:

all you need is a mundane xsl:if :thumbsup:

<xsl:template match="system-folder">

<li>
<xsl:if test="position() = 1">
<xsl:attribute name="class">first</xsl:attribute>
</xsl:if>
<a>
<xsl:attribute name="href">
<xsl:value-of select="system-page[name = 'index']/path"/>
</xsl:attribute>

<xsl:call-template name="get-name"/>
</a>
</li>
<xsl:if test="count(system-page) = 1">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="system-page/path" />
</xsl:attribute>
<xsl:value-of select="system-page/name" />
</a>
</li>
</xsl:if>
</xsl:template>

ynotlim
02-26-2009, 11:02 PM
thanks worked like a charm



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum