Search code examples
asp.netxslttridiontridion-2011

How to transform sitemap XML file into breadcrumb using XSLT in SDL Tridion?


I have a XML file for sitemap, here it is:

<?xml version="1.0" encoding="utf-8"?>
<siteMap>
  <siteMapNode url="/" title="Home" tcmId="tcm:142-2-4">
    <siteMapNode url="/controls" title="Controls" tcmId="tcm:142-1131-4" type="structure group" />
    <siteMapNode url="/css" title="CSS" tcmId="tcm:142-1134-4" type="structure group" />
    <siteMapNode url="/js" title="JS" tcmId="tcm:142-1133-4" type="structure group" />
    <siteMapNode url="/xslt" title="XSLT" tcmId="tcm:142-1132-4" type="structure group"   />
    <siteMapNode url="/mobile" title="Mobile" tcmId="tcm:142-1165-4" type="structure group" />
    <siteMapNode url="/mobilebiscuitml" title="Mobile BiscuitML" tcmId="tcm:142-1180-4" type="structure group" />
    <siteMapNode url="/system" title="system" tcmId="tcm:142-136-4" type="structure group">
    <siteMapNode url="/system/captcha" title="Captcha" tcmId="tcm:142-260-4" type="structure group" />
    <siteMapNode url="/system/communicator" title="Communicator" tcmId="tcm:142-201-4" type="structure group" />
    <siteMapNode url="/system/errorpages" title="Error Pages" tcmId="tcm:142-322-4" type="structure group" />
    <siteMapNode url="/system/includes" title="includes" tcmId="tcm:142-138-4" type="structure group" />
    <siteMapNode url="/system/masterpages" title="Master Pages" tcmId="tcm:142-139-4" type="structure group" />
    <siteMapNode url="/system/outboundemail" title="Outbound Email" tcmId="tcm:142-199-4" type="structure group" />
    <siteMapNode url="/system/SiteEdit" title="SiteEdit" tcmId="tcm:142-214-4" type="structure group" />
    <siteMapNode url="/system/ui_widgets" title="UI Widgets" tcmId="tcm:142-320-4" type="structure group" />
    <siteMapNode url="/system/webtemplates" title="Web Templates" tcmId="tcm:142-333-4" type="structure group" />
    <siteMapNode url="/system/xml" title="Xml" tcmId="tcm:142-141-4" type="structure group" />
  </siteMapNode>
  <siteMapNode url="/App_GlobalResources" title="Website Labels" tcmId="tcm:142-295-4" type="structure group" />
    <siteMapNode url="/Bpo.aspx" title=" BPO" tcmId="tcm:142-10830-64" type="page" />
    <siteMapNode url="/Careers.aspx" title=" Careers" tcmId="tcm:142-10692-64" type="page" />
    <siteMapNode url="/bpoHitech.aspx" title=" Hitech" tcmId="tcm:142-10710-64" type="page" />
    <siteMapNode url="/news.aspx" title=" News" tcmId="tcm:142-10868-64" type="page" />
    <siteMapNode url="/ISD.html" title="ISD" tcmId="tcm:142-11027-64" type="page" />
    <siteMapNode url="/Services.aspx" title="Services" tcmId="tcm:142-10681-64" type="page" />
    <siteMapNode url="/Knowledge.aspx" title="Knowledge" tcmId="tcm:142-11170-64" type="page" />
  </siteMapNode>
</siteMap>

What i've did till now: create a function in script tag in PT DWT TBB. where, pageload() { id="@@Page.ID@@" } this TBB inherits a (.cs file) where i defined a id property in a class. create a object of this class type and access the property. used this property as XSLT argument and apply the transformation through xsl.

Any other suggestion'd be good.


Solution

  • Manoj, The below XSL might help.. I have not tested this, but used it in some past projects the xml structure is slightly different but the below snippet should help you on moving forward in the right direction.

     <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:template match="/">
            <xsl:for-each select="//siteMapNode[@title = '<<Controls>>']">  ---> Node title of the current page
                <div id="breadcrumb">
                    <xsl:for-each select="ancestor::siteMapNode"> --> selects the parent and loop through.. 
                        <a href="@url"><xsl:value-of select="@title"/></a> &gt; --> breadcrumb separator ">"
                    </xsl:for-each>
                    <xsl:value-of select="@title"/>
                </div>
            </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>