Solved

Generate breadcrumb from OPML

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

18 Experts available now in Live!

Get 1:1 Help Now