xsl-list
[Top] [All Lists]

RE: Generate Yahoo-like directory structure

2004-05-11 09:44:23
Much easier in 2.0: use tokenize() to split the path into a sequence of
names, then use a recursive function:

<xsl:function name="f:probe" as="node()*">
  <xsl:param name="origin" as="node()*/>
  <xsl:param name="path" as="xs:string*"/> 
  <xsl:sequence select="if (empty($path))
                        then $origin
                        else f:probe($origin/element[(_at_)name=$path[1]],
                                     remove($path,1))"/>
</xsl:function>

<xsl:param name="path" as="xs:string" required="yes"/>

<xsl:template match="/"> 
  <xsl:copy-of select="f:probe(., tokenize($path, '/'))"/>
</xsl:template>

In 1.0 you can use similar logic but it will be much more verbose, and
you'll have to output the copied subtree from the innermost level of
call-template rather than from the outermost template as here.


Michael Kay



-----Original Message-----
From: Philipp Burkert [mailto:mailings(_at_)burkert(_dot_)de] 
Sent: 11 May 2004 14:53
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Generate Yahoo-like directory structure

Hej folks,

I am sorry, if this has been asked before, but I did research 
on the FAQ and
the mailing list archive and could not find any information. 
It would be
nice if someone could help me or give me a link to a thread 
where it has
been discussed.

My target is to build a HTML based yahoo-like directory 
structure out of a
single XML file. The file looks somewhat like this.

<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>

As a XSL param I could offer a path like "Main/Business/" 
that identifies
the page that should be generated. The page to be generated 
should contain
all subelements to the "Business" element and a list of 
parent elements that
can be used to generate a Navigation menue. (In this case 
only finance, of
course.) 

This task looks so common I really wonder why I can not find anything
online. Thankx for your help in advance.

Best Regards

PHILIPP BURKERT
mailings(_at_)burkert(_dot_)de


--+------------------------------------------------------------------
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>