Solved

Generate breadcrumb from OPML

Posted on 2006-07-15
3
227 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
read PayflowPro reports using the report metadata using perl 11 36
Change to event 1 101
API Soap Calls 4 89
JQuery to parse xml string and get element by id 4 23
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now