xsl-list
[Top] [All Lists]

RE: Dmoz xml structure sort

2004-04-21 09:38:54
I love it, great solution.

Question though,
Is there a way to apply this idea to this structure?

<?xml version="1.0" encoding="UTF-8"?>
<iThink.ePulp xmlns:r="http://www.w3.org/TR/RDF/";
xmlns:d="http://purl.org/dc/elements/1.0/";>
        <Structure>
                <Topic r:id="Base">
                        <tag catid="1"/>
                        <d:Title local="en-US">Home</d:Title>
                        <near resource="Base/General_Information"/>
                        <near resource="Base/StudentLife"/>
                        <near resource="Base/Missions"/>
                        <near resource="Base/Community"/>
                        <near resource="Base/Academics"/>
                        <near resource="Base/News"/>
                </Topic>
                <Topic r:id="Base/General_Information">
                        <tag catid="2"/>
                        <d:Title local="en-US">General Information</d:Title>
                        <near
resource="Base/General_Information/Staff_Directory"/>
                </Topic>
                <Topic r:id="Base/General_Information/Staff_Directory">
                        <tag catid="8"/>
                        <d:Title local="en-US">Staff Directory</d:Title>
                </Topic>
                <Topic r:id="Base/StudentLife">
                        <tag catid="3"/>
                        <d:Title local="en-US">Student Life</d:Title>
                        <near resource="Base/StudentLife/Important_Dates"/>
                </Topic>
                <Topic r:id="Base/Missions">
                        <tag catid="4"/>
                        <d:Title local="en-US">Missions</d:Title>
                        <near resource="Base/Missions/National_Missions"/>
                        <near
resource="Base/Missions/International_Missions"/>
                </Topic>
                <Topic r:id="Base/Missions/National_Missions">
                        <tag catid="9"/>
                        <d:Title local="en-US">National Missions</d:Title>
                </Topic>
                <Topic r:id="Base/Missions/International_Missions">
                        <tag catid="10"/>
                        <d:Title
local="en-US">InternationalMissions</d:Title>
                </Topic>
                <Topic r:id="Base/Community">
                        <tag catid="5"/>
                        <d:Title local="en-US">Community</d:Title>
                        <near
resource="Base/Community/Upcoming_Outreaches"/>
                        <near resource="Base/Community/Past_Outreaches"/>
                </Topic>
                <Topic r:id="Base/Academics">
                        <tag catid="6"/>
                        <d:Title local="en-US">Academics</d:Title>
                        <near resource="Base/Academics/Classes"/>
                        <near resource="Base/Academics/Schedule_Calendar"/>
                </Topic>
                <Topic r:id="Base/News">
                        <tag catid="7"/>
                        <d:Title local="en-US">News &amp; Events</d:Title>
                        <near resource="Base/News/Item1"/>
                </Topic>
        </Structure>
</iThink.ePulp>

-----Original Message-----
From: Robert Koberg [mailto:rob(_at_)koberg(_dot_)com] 
Sent: Sunday, April 18, 2004 10:15 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Dmoz xml structure sort

Hi,

I think you are on the right track, but I would suggest changing your 
schema a bit. I would organize your topics hierarchically and have a 
unique ID and a name (names are more likely to have duplicates) 
attribute, like:

<topic id="t123" name="Base">
   <Title local="en-US">Home</Title>
   <topic id="t234" name="General_Information">
     <topic id="t345" name="About_us">

     </
     <topic id="t346" name="Contact_us">

     </
   </
</

With this structure you will be able to many more things than you have 
probably thought of at this point and you do not need to list the 
//narrow elements because they are now there. This means you can move 
things around and you wont' have to edit your topics config.

Now, on to some XSL:

First thing to do is create a top level key:

<xsl:key name="topics" match="topic" use="@id"/>

Then I usually pass the 'focus' id into the transformation as a 
parameter, so if you can do that you can get your focus topic in a top 
level variable:

<xsl:variable
   name="focus_topic"
   select="key('topics', $focus_topic_id)"/>

<xsl:variable
   name="focus_parent"
   select="key('topics', $focus_parent_id)"/>

Then you can use this variable throughout your transformation to find 
your topic context. You can ensure you always have valid links by first 
going to the linked topic nodeset and then traveling up and down the 
topic hierarchy to find the path. Say you want to create a nav thingy - 
you can do it like so:

<xsl:template match="/">
   <html>
     <xsl:call-template name="head"/>
     <body>
       <div id="pageBody">
         <xsl:call-template name="banner"/>

         <div id="navColumn">

           <xsl:apply-templates
             select="$focus_parent/*"
             mode="navigation"/>

         </div>

         <div id="contentWrapper">
           <xsl:appl
         <xsl:call-template name="footer"/>
       </div>
     </body>
   </html>
</xsl:template>


<!-- match the children of the focus parent-->
<xsl:template match="*" mode="navigation">

   <xsl:variable name="href">
     <xsl:call-template name="topic_path_builder"/>
   </

   <xsl:choose>
     <xsl:when test="not(@id=$focus_topic_id)">
       <div>
         <a href="{$href}">
           <xsl:value-of select="@label"/>
         </a>
       </div>
     </
     <xsl:otherwise>
       <div class="selected">
         <a href="{$href}">
           <xsl:value-of select="@label"/>
         </a>
       </div>
     </
   </
</

<xsl:template name="topic_path_builder">
   <xsl:call-template name="ancestor_path"/>
   <xsl:text>/</xsl:text>
   <xsl:value-of select="@name"/>
</xsl:template>

<!-- root relative paths,
you could do document relative paths too-->

<xsl:template name="ancestor_path">
   <xsl:for-each select="ancestor::*">
     <xsl:text>/</xsl:text>
     <xsl:value-of select="@name"/>
   </xsl:for-each>
</xsl:template>

make sense?

best,
-Rob



John Hamman wrote:

Hi all.
I have a navigational site tree xml page similar to Dmoz.org.
And its made up like this below. I am new to xpath and am having problems
finding a solution to this.

My file looks similar to this.

<Topic id="Base">
                      <tag catid="1"/>
                      <Title local="en-US">Home</Title>
                      <narrow resource="Base/General_Information"/>
                      <narrow resource="Base/StudentLife"/>
                      <narrow resource="Base/Missions"/>
                      <narrow resource="Base/Community"/>
                      <narrow resource="Base/Academics"/>
                      <narrow resource="Base/News"/>
              </Topic>
              <Topic id="Base/General_Information">
                      <tag catid="2"/>
                      <Title local="en-US">General Information</Title>
                      <narrow
resource="Base/General_Information/About_us"/>
                      <narrow
resource="Base/General_Information/Contact_us"/>
                      <narrow
resource="Base/General_Information/Directors_Letter"/>
                      <narrow
resource="Base/General_Information/History"/>
                      <narrow
resource="Base/General_Information/What_We_Beleive"/>
                      <narrow
resource="Base/General_Information/Staff_Directory"/>
              </Topic>
              <Topic id="Base/General_Information/About_us">
                      <tag catid="8"/>
                      <Title local="en-US">About Us</Title>
              </Topic>
              <Topic id="Base/General_Information/Contact_us">
                      <tag catid="9"/>
                      <Title local="en-US">Contact Us</Title>
              </Topic>
...
...
...


And I want to acheave results like this if I had a dynamic variable like 
"Base/General_Information/About_us"

<Topic id="Base/General_Information/About_us">
                      <tag catid="8"/>
                      <Title local="en-US">About Us</Title>
              </Topic>
              <Topic id="Base/General_Information/Contact_us">
                      <tag catid="9"/>
                      <Title local="en-US">Contact Us</Title>
              </Topic>
              <Topic id="Base/General_Information/Directors_Letter">
                      <tag catid="10"/>
                      <Title local="en-US">Letter From the
Director</Title>
              </Topic>
              <Topic id="Base/General_Information/History">
                      <tag catid="11"/>
                      <Title local="en-US">History</Title>
              </Topic>
              <Topic id="Base/General_Information/What_We_Beleive">
                      <tag catid="12"/>
                      <Title local="en-US">What We Beleive</Title>
              </Topic>
              <Topic id="Base/General_Information/Staff_Directory">
                      <tag catid="13"/>
                      <Title local="en-US">Staff Directory</Title>
              </Topic>

Can someone point me in the right direction?
john


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




<Prev in Thread] Current Thread [Next in Thread>