Solved

Generate breadcrumb from OPML

Posted on 2006-07-15
3
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

751 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