Hi Ard,
I did, in fact, get it to work with some tweaking of the xsl. The
snippets follow.
What I would like to do now is strip the ".xml" file extension from the
resulting href in the html. Suggestions?
Joe
P.S. Here is what works.
>From this sitemap matcher...
<map:match pattern="articles/">
<map:generate type="xpathdirectory" src="articles">
<map:parameter name="xpath" value="/topic/title"/>
<map:parameter name="xmlFiles" value="\.x.*$"/>
</map:generate>
<map:transform src="mydir2html.xsl"/>
<map:serialize type="html"/>
</map:match>
...we get the title of each article for use as text in the resulting
html <a> element.
The following xsl...
<xsl:template match="/dir:directory">
<xsl:apply-templates select="dir:directory"/>
</xsl:template>
<xsl:template match="dir:directory">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="dir:file">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:apply-templates select="dir:xpath"/>
</xsl:element>
</xsl:template>
<xsl:template match="dir:xpath">
<xsl:value-of select="title"/>
</xsl:template>
...uses the name attribute of each file in the XPathGenerator result as
the href of the <a> elements in the resulting html...
<html>
<head>
<title/>
</head>
<body>
<table id="body">
<tr>
<td id="articles">
<h4 class="menuheader">Articles</h4>
<a href="article1.xml">Article the first</a>
<a href="article2.xml">Article the second</a>
</td>
</tr>
</table>
</body>
</html>
...which is all ready for tweaking and CSS-ifying and whatever you want
to do to it.
On Mon, 2006-11-06 at 21:28 +0100, Ard Schrijvers wrote:
> Hello,
>
> did you manage to get it to work? Think you have some problems with xml/xsl
> transformations. Also take into account the namespaces. If you are still
> having problems, please let us know, or subscribe to some xsl mailinglist,
> like http://www.mulberrytech.com/xsl/xsl-list/.
>
> Your problem is only xsl related, not browser.
>
> Regards
>
>
> >
> > I would like to be able to drop valid xml files into a directory and
> > have them appear automagically in a menu, with the ability to
> > transform
> > the title of the article in the file into the text of a link
> > if I want.
> >
> > I get the XPathDirectory generator to work with the following pipeline
> > matcher.
> >
> > <map:match pattern="articles/*">
> > <map:generate type="xpathdirectory" src="articles/{1}">
> > <map:parameter name="xpath" value="title"/>
> > <map:parameter name="xmlFiles" value="\.x.*$"/>
> > </map:generate>
> > <map:serialize type="xml"/>
> > </map:match>
> >
> > The above matcher produces the following output.
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
> > name="articles" lastModified="1162301516000" date="31/10/06 07:31"
> > size="4096" sort="name" reverse="false" requested="true">
> > <dir:file name="article1.xml" lastModified="1162312230000"
> > date="31/10/06 10:30" size="136">
> > <dir:xpath query="title">
> > <title>Article title</title>
> > </dir:xpath>
> > </dir:file>
> > </dir:directory>
> >
> > So far, so good.
> >
> > However, I would like to transform the XML so I can do other
> > things with
> > it, such as a quick and dirty dynamic HTML menu or aggregate into
> > another web page as XML and subsequently transform the title elements
> > into links. I have attempted the following.
> >
> > <xsl:template match="/">
> > <xsl:apply-templates/>
> > </xsl:template>
> >
> > <xsl:template match="article">
> > <xsl:value-of select="title"/>
> > </xsl:template>
> >
> > When I add this XSL to the matcher, still serializing as XML
> > I get this
> > result (when viewing the source).
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>Article title
> >
> > Which looks OK, but Firefox complains with the following error.
> >
> > XML Parsing Error: syntax error
> > Location: http://localhost:8080/sandbox/articles/
> > Line Number 1, Column 44:<?xml version="1.0"
> > encoding="ISO-8859-1"?>Article title
> > -------------------------------------------^
> > Why is it encoded as ISO-8859-1? Everything in my sitemap says UTF-8.
> >
> > This happens regardless of the charset I specify in Firefox.
> > Amaya also
> > complains.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]