Solved

Generate breadcrumb from OPML

Posted on 2006-07-15
3
229 Views
Last Modified: 2007-12-19
Using this xml example below, I want to generate an html output that look like this. there's a global param iamhere being set, so it depends on where the iamhere param is, that's the self node in the document.

<xsl:apply-templates select="//BBB[@ss = $iamhere]" mode="BBB-getallparents"/>

<!-- HTML -->

<div id="breadcrumb">
<ul><li><a href="http://www.abc.com/222">Ancestor Node</a>
        <ul><li><a href="http://www.abc.com/200">Parent Node</a>
                <ul><li><span>232 - Self Node</span><ul /></li></ul>
        </li></ul>
</li></ul>
</div>


<!-- XML -->

<AAA>
     <HHH>
     <BBB rr= "111" ss= "222">
          <BBB rr= "100" ss= "200">
               <BBB rr= "131" ss= "232"> <-- matching node
                     <BBB rr="000" ss="001">
                           <BBB rr="002" ss="002"></BBB>                          
                     </BBB>
               </BBB>
               <BBB rr= "161" ss= "299"></BBB>
           </BBB>
          <BBB rr= "101" ss= "202"></BBB>
          <BBB rr= "191" ss= "234"></BBB>
      </BBB>
     <BBB rr= "222" ss= "333">
          <BBB rr= "331" ss= "532"></BBB>
          <BBB rr= "121" ss= "332"></BBB>
          <BBB rr= "631" ss= "432"></BBB>
     </BBB>
     <BBB rr= "444" ss= "555">
          <BBB rr= "135" ss= "732"></BBB>
     </BBB>
     </HHH>
</AAA>

0
Comment
Question by:etherealz
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 17114696
Hi etherealz,

variations on a theme, I like that...

try this one
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:param name="iamhere" select="299"/>
   
    <xsl:template match="/">
        <xsl:apply-templates select="//BBB[@ss = $iamhere]" mode="BBB-getallparents"/>
    </xsl:template>
   
    <xsl:template match="BBB" mode="BBB-getallparents">
        <div id="breadcrumb">
            <xsl:call-template name="buildTree">
                <xsl:with-param name="curNode" select="ancestor-or-self::BBB[not(ancestor::BBB)]"></xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>
   
    <xsl:template name="buildTree">
        <xsl:param name="curNode"/>
        <xsl:choose>
            <xsl:when test="$curNode/@ss = $iamhere">
                <ul><li><span><xsl:value-of select="$iamhere"/><xsl:text> - Self Node</xsl:text></span></li></ul>
            </xsl:when>
            <xsl:otherwise>
                <ul>
                    <li><a href="http://www.abc.com/{$curNode/@ss}"><xsl:value-of select="$curNode/@ss"/><xsl:text> - Ancestor Node</xsl:text></a>
                        <xsl:call-template name="buildTree">
                            <xsl:with-param name="curNode" select="$curNode/BBB[descendant-or-self::BBB[@ss = $iamhere]]"></xsl:with-param>
                        </xsl:call-template>
                    </li>
                </ul>
            </xsl:otherwise>
        </xsl:choose>
       
    </xsl:template>
   
</xsl:stylesheet>


Cheers!
0
 

Author Comment

by:etherealz
ID: 17115314
Thanks! Works very well!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 17115688
cheers
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question