[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Generate Yahoo-like directory structure

Subject: RE: Generate Yahoo-like directory structure
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Thu, 20 May 2004 01:46:57 -0600
free yahoo like directory
Hey Daniel,

Yes and No...

All of my sites are generated eventually using XML + XSLT.  However, I
never even go as far as typing "<?" before I design both the graphics
and the associated HTML independent of any sort of transformation
process.  Its not until I have solved all of the potential layout issues
and have dealt with all of the intricacies of making a site look the
same on the core base of browsers (Generally speaking I use Mozilla as a
core reference and then adjust for the rest of the browser base
(pre-Mozilla Netscape, IE 5.x+, Thunderbird (as its nice to see how my
code of today will/may render in the Mozilla of tomorrow), Netscape
6.x+, and, sometimes, Opera (that's only because when that moment comes
that my code renders, for the most part, exactly the same in all of the
other browsers its fun to look to see if even Opera renders it
correctly...) that I break apart the HTML into its respective data and
rendering code pieces to then convert into XML and XSLT.

You may notice when you look at generationXML.com that the underlying
code is a 100% CSS/Layer base.  I made the decision about 6 months ago
to convert all of my HTML work over to a CSS/Layer base, doing away with
tables all together.  I realize that there are times when tables are
useful (displaying tabular data for example) but I had reached the end
of my layout rope when it came to tables and I decided the time had come
to make the switch.  Actually, during this same 6 month period I have
been developing a library of XSLT templates that auto-generate CSS/Layer
layout code using a XAML type XML description language.  As such I have
been able to limit the amount of time building the underlying layout
code as once Ive been able to create a code base that proves to render
the same on every major platform I convert it to a generic/reusable XSLT
template or combination of templates and add it to my library.  Its then
just a matter of creating an XML element that uses the proper name and
associated attributes (e.g. <box width="500" height="200" margin="0px
0px 0px 0px"> insert data </box>) to tell the XSLT layout engine what
template or combination of templates to use to generate the desired
CSS/Layer based output.  Im not there yet, but I am getting the library
to the point where I know longer have to worry about whether the
CSS/Layer code is going to render the way I expect it to in every major
browser.  When the time comes that I have developed the library to the
point that it can generate 100% error free CSS/Layer code I plan on
making it available for everyone else to use and enjoy in there own
development.  If your interested, let me know and Ill add you to my list
of people to send the URI to when I publish this library to the web.
Use my regular email to let me know of your interest
(m.davidATmdptwsDOTcom or mdptwsATmsnDOTcom if my spam filter doesn't
like you for some reason ;) ) as I wouldn't want to be filling the
inboxes of everyone on this list with personal requests to be added to
the distro for the announcement of the release and URI location of this
library (it will be 100% free and 100% open source).

Based on the subject of this original thread I am unclear if you have
any specific questions regarding the Yahoo! style directory XSLT engine
that I created and posted a few weeks back.  If so, let me know and I
will respond back with more specifics to this particular topic.

Hope this helps answer your question(s)!

Best regards,

<M:D/>

> -----Original Message-----
> From: Daniel Joshua [mailto:daniel.joshua@xxxxxxxxxxxx]
> Sent: Thursday, May 20, 2004 12:51 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Generate Yahoo-like directory structure
> 
> David
> 
> >http://www.generationXML.com
> 
> Did you generate this whole site with XML + XSLT?
> 
> I am trying to the above, so just interested...
> 
> 
> Regards,
> Daniel
> 
> 
> -----Original Message-----
> From: M. David Peterson [mailto:m.david@xxxxxxxxxx]
> Sent: Wednesday, 12 May, 2004 10:06 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Generate Yahoo-like directory structure
> 
> 
> When I saw your post it reminded me that I needed to create this exact
> feature for an up and coming site of mine,
http://www.generationXML.com
> http://www.aspectXML.org has taken precedence simply because the
benefit
> of having the AspectXML project in a 1.0 state will benefit greatly
> generationXML.com as well as several of my other projects.  I realize
> this is a lot more information than you needed but I thought I would
> explain that in this particular case I am not trying to be the good
> Samaritan who simply wants to help where he can.  No my motives were
> ulterior this time around but fortunately the fact that I needed this
> code and had planned on writint it this week lends well to all of us.
> 
> As it turns out the code took less than an hour to develop so it
wasn't
> even as big of a deal as I thought it would be. The resulting code
> should do for you exactly what you want... output a Yahoo style
> directory based on a parameter that is set to the current directory
> structure and then mapping that against an XML tree that we can then
> parse to output our desired directory... fortunately our needs were
> exact and we both now have what we want.  Well, I hope anyway :D
> 
> I apologize for not getting this done and out sooner but the events of
> the day have not lent well to such luxuries so it is now almost 8pm
> where I'm at and the day isn't even close to coming to an end.  Such
is
> the life of a software developer/code junkie.
> 
> I'll provide some quick documentation to try to explain what I did.
If
> this becomes code that gets used by more than one person I may
consider
> writing heavier docs but these should be suffice to anyone but the
> novice XSLT developer.
> 
> Keep in mind that I've only done preliminary testing on this code but
so
> far is seems to output correctly the children of the last element in
the
> directory structure.  A great contribution back for developing this
code
> would be to test it until it begs for mercy (try going 20 or 30 (or
even
> 40 or 50 if you feel brave) levels deep and then process as many
> children as you have the patience to create in your sample XML file)
and
> then post back your results to the list so that everyone can benefit
> from it.
> 
> I still like Michael Kay's solution a million times better (he tends
to
> write pretty good code ;) but I, like you, have to use 1.0 code for
the
> time being in production so until the day comes that 2.0 is a choice
> this will have to do.
> 
> A quick synopsis of the code:
> 
> 	- I first created a param called 'dirPath' and set it to my
> desired test setting, in this case I set it to 'Main/Computers/WWW'.
> 
> 	- I then created my first template and matched it to root.
> 
> 	- Within this first template I created a variable called
> 'dirPathXML' and used call-template to call the 'PathToXML' template
> passing it the param 'dirPath' set to the value of the global param
> 'dirPath'.
> 
> 	- Within this template I used a named-template and called it
> recursively to build an XML data set from the directory structure.
The
> code should be pretty straight forward in how this works but in
general
> it parses the string using the '/' and the current string-length to
> determine if it should keep recursively building the tree.  Actually,
it
> first tests to see if '/' is the first character of the string and if
so
> calls the template again but this time setting the value of dirPath to
> the substring-after '/'.  With this we have allowed ourselves the
> ability to test for the presence of '/' as well as the string-length
> after the first (and potentially last) occurrence of '/' to determine
if
> we need to call the template again to catch the remaining values and
put
> them into the tree structure.  This test statement:
> 
> 	string-length(substring-after($dirPath, '/')) &gt; 0
> 
> will both test for the presence of '/' as well as check the length of
> the string contained after '/' if it finds it.  Obviously if the
> substring-after function doesn't find an occurrence of '/' the entire
> equation will evaluate to false causing the code to fall-through to
the
> next 'when' block if present or 'otherwise' block if not. If this
> happens the only thing left to test for is if there's a '/' at end of
> our string (depending on how the directory structure was passed in
there
> may be a '/' appended to the end).  If there is we need to get rid of
it
> and then write out the string (the string becomes the value of the
> 'name' attribute of 'element' btw...) to the output otherwise just
write
> out the string.  The next 'when' and 'otherwise' block take care of
this
> for us.
> 
> At this point we have contained in our variable a data set that looks
a
> lot like XML.  However, if we tried to use this variable as the basis
of
> a select attribute of apply-templates or for-each we would find an
error
> thrown.  Even though it looks to us like XML it looks like a string or
> at best a result tree fragment to the processor and as such we need to
> tell the processor to treat this like regular old XML data.  In 1.0
the
> only way to do this is with an extension function.  If your processor
> doesn't support some sort of nodeset() extension function then you are
> most likely not using one of the standard processors as all of the
> standard processor vendors utilize some form of the nodeset() function
> to allow you to convert transformed data we have stored into a
temporary
> tree or current flow of the processor into something that we can now
> continue to parse as if it was part of the existing XML data flow.
Ive
> used Xalan in this example but msxml uses the msxml namespace and
> implements using msxml:node-set() while Saxon uses the EXSLT library
to
> invoke the conversion which uses the exslt namespace and
> exslt:node-set() to invoke the function (this would be in place of
> xalan:nodeset() which is currently being used.)  Remember to add the
> correct xmlns: statement to the xsl:stylesheet declaration to ensure
> things go over smoothly.  Just look to the docs for whichever
processor
> you use to show how to do this correctly.
> 
> Once we have our nodeset we can simply use apply-templates and the
> elements of the variable we created to continue the processing.  By
> passing as a parameter the value of the current directory structure we
> can then match each element with the element contained in our
variable,
> recursively parsing the children of our created nodeset until we find
> there are no more children to process.  When this happens we know we
> have reached the end of our directory structure (and the whole time we
> have been continuing to water down the directory structure using the
> name attribute as reference and passing it back to the template as a
> parameter) and if we have matched the names of the directory structure
> correctly with element names of our directory we can now
apply-templates
> to the children of the current element in context and process them as
we
> wish to get the desired styled output.
> 
> Note: Notice the use of mode="..." in both the call to apply-templates
> as well as the template it matches to. This ensures that the processor
> knows which template to process the current 'element' element with as
> otherwise it would just use the first template that matched 'element'
> which obviously wouldn't work in every case.
> 
> I have just put some basic formatting in as the way I plan on
outputting
> the directory structure may be different form how you would want to do
> it.  However, I will make available (on generationXML.com if I ever
get
> it finished ;) the implementation that I develop simply because it
will
> be table-less and driven by CSS classes and as such completely
> customizable via these same classes making it a pretty universal
> solution.  Im not sure when ill get that done but it will be soon and
I
> will post a link to the list when it happens.  In the mean time, enjoy
> the following code and please, if you have the time to pressure cook
it,
> it would be a huge help and will benefit all the members of the list
and
> beyond (if they of course were to choose to use this code for there
own
> project :)
> 
> Also, keep in mind that I wrote this in less than an hour and although
> conceptually it seems sound I could be completely missing something I
> haven't even thought of.  So, if you have any suggestions on how to
make
> this better, faster, more robust, etc... feel free to make the changes
> yourself or let me know your thoughts and Ill see if I can incorporate
> them.
> 
> Hope this helps!
> 
> Best regards,
> 
> <M:D/>
> 
> The following XML:
> <?xml version="1.0"?>
> <element name="Main">
>   <element name="Business">
>     <element name="Finance"/>
>   </element>
>   <element name="Computers">
>     <element name="Internet"/>
>     <element name="WWW">
>       <element name="Chat"/>
>       <element name="DNS"/>
>     </element>
>   </element>
>   <element name="Business"/>
> </element>
> 
> When processed by this XSLT:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>     xmlns:xalan="http://xml.apache.org/xalan"
>     version="1.0">
>   <xsl:param name="dirPath" select="'Main/Computers/WWW'"/>
> 
>   <xsl:output method="html" indent="yes"/>
>   <xsl:template match="/">
>     <xsl:variable name="dirPathXML">
>       <xsl:call-template name="PathToXML">
>         <xsl:with-param name="dirPath" select="$dirPath"/>
>       </xsl:call-template>
>     </xsl:variable>
>     <xsl:variable name="dirXML" select="xalan:nodeset($dirPathXML)"/>
>     <xsl:apply-templates select="$dirXML/*" mode="locDir">
>       <xsl:with-param name="directory" select="*"/>
>     </xsl:apply-templates>
>   </xsl:template>
>   <xsl:template name="PathToXML">
>     <xsl:param name="dirPath"/>
>     <xsl:choose>
>       <xsl:when test="starts-with($dirPath, '/')">
>         <xsl:call-template name="PathToXML">
>           <xsl:with-param name="dirPath"
> select="substring-after($dirPath, '/')"/>
>         </xsl:call-template>
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:element name="element">
>           <xsl:choose>
>             <xsl:when test="string-length(substring-after($dirPath,
> '/')) &gt; 0">
>               <xsl:attribute name="name">
>                 <xsl:value-of select="substring-before($dirPath,
'/')"/>
>               </xsl:attribute>
>               <xsl:call-template name="PathToXML">
>                 <xsl:with-param name="dirPath"
> select="substring-after($dirPath, '/')"/>
>               </xsl:call-template>
>             </xsl:when>
>             <xsl:when test="contains($dirPath, '/')">
>               <xsl:value-of select="substring-before($dirPath, '/')"/>
>             </xsl:when>
>             <xsl:otherwise>
>               <xsl:value-of select="$dirPath"/>
>             </xsl:otherwise>
>           </xsl:choose>
>         </xsl:element>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
>   <xsl:template match="element" mode="locDir">
>     <xsl:param name="directory"/>
>     <xsl:variable name="name" select="@name"/>
>     <xsl:choose>
>       <xsl:when test="*">
>         <xsl:apply-templates select="*" mode="locDir">
>           <xsl:with-param name="directory" select="$directory[@name =
> $name]/*"/>
>         </xsl:apply-templates>
>       </xsl:when>
>       <xsl:otherwise>
>         <table>
>           <tr>
>             <xsl:apply-templates select="$directory[@name = $name]/*"
> mode="outputYahoo"/>
>           </tr>
>         </table>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
>   <xsl:template match="element[last()]" mode="outputYahoo">
>     <td>
>       <a href="{@name}">&#160;<xsl:value-of select="@name"/>&#160;</a>
>     </td>
>   </xsl:template>
>   <xsl:template match="element" mode="outputYahoo">
>     <td>
>       <a href="{@name}">&#160;<xsl:value-of select="@name"/>&#160;</a>
>     </td>
>     <td>|</td>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> Will return the following HTML to the output:
> 
> <table>
>   <tr>
>     <td><a href="Chat">&nbsp;Chat&nbsp;</a></td><td>|</td><td><a
> href="DNS">&nbsp;DNS&nbsp;</a></td>
>   </tr>
> </table>
> 
> Again, feel free to modify, enhance, or suggest enhancements...  And
if
> you come up with something really sweet please post it back for the
rest
> of us to enjoy :D
> 
> Thanks!
> 
> <M:D/>
> 
> > -----Original Message-----
> > From: Philipp Burkert [mailto:mailings@xxxxxxxxxx]
> > Sent: Tuesday, May 11, 2004 11:07 AM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: RE:  Generate Yahoo-like directory structure
> >
> > Hi,
> >
> > Michael, thankx for the quick response. Anyhow I should have made a
> note
> > that I can not make use of Xpath2. Can you - or someone else -
outline
> the
> > way in Version 1 in more detail?
> >
> > Thankx
> >
> > PHILIPP BURKERT
> > mailings@xxxxxxxxxx

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.