Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Generate breadcrumb from OPML

Posted on 2006-07-15
3
Medium Priority
?
235 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 1000 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

704 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