Adrian von Bidder
Usenet Archive
- Joined
- Apr 9, 2006
- Messages
- 2
- Reaction score
- 0
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Yo!
Mostly as a finger-exercise (and because I'm annoyed again and again how bad the existing solutions are), I'm hacking up a web-based forum (yes, the 64832th one, I know).
I want to allow some simplified HTML as input language, and use some xsl to render that afterward. I do simple verification with a DTD (no problem in that), but the rendering into html is where I'm stuck currently.
The articles are stored as:
=====
<article>
<head>
<author>squiggle</author>
<title>Quack</title>
<date>2006-02-26 15:07:12</date>
</head>
<body>Says the Duck.</body>
</article>
=====
The body can be plain text, but mostly it should be simple HTML. I decided on the following feature set: <em>, <tt>, <p>, <a href="">, <img alt="" src=""> should be passed through unchanged. <title> should be changed to <h3>, and <blockquote cite="url"> should be changed to something like <div><blockquote cite="url">'the quote'</blockquote><div><a href="url">url</a></div></div>, if an URL is present, or only blockquote else.
The whole should be wrapped within some <div>'s, showing article title, author, date etc.
Now I've written some small piece of XSL:
=====
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl
utput method="xml" omit-xml-declaration="yes"/> <xsl:strip-space elements="*"/>
<!-- title becomes h3 -->
<xsl:template match="title">
<h3><xsl:apply-templates/></h3>
</xsl:template>
<!-- blockquote gets visible citation -->
<xsl:template match="blockquote">
<xsl:element name="blockquote">
<xsl:attribute name="cite">
<xsl:value-of select="@cite"/>
</xsl:attribute>
<div class="text"><xsl:apply-templates/></div> <div class="cite"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@cite"/> </xsl:attribute> <xsl:value-of select="@cite"/> </xsl:element> </div> </xsl:element> </xsl:template>
<!-- a, em, img, p, tt go through unchanged -->
<xsl:template match="a|em|img|p|tt">
<xsl:copy>
<xsl:apply-templates select="@*|node"/>
</xsl:copy>
</xsl:template>
<!-- the complete head is stripped out -->
<xsl:template match="head">
</xsl:template>
</xsl:stylesheet>
=====
And I'm right now extracting article titles etc. manually from the perl code, and calling the xsl only on the body element. But this is not really what I want... The point where I'm stuck is with the rules which part of the xsl is called at which point on which part of the xml file. And also: I'll certainly need to filter the img and a tags, because I *only* want to allow the attributes I've talked about above. (OTOH this is already taken care of by the DTD, so maybe I just won't care.)
Pointers welcome, but most of the tutorials I've found so far stopped where things got really interesting. Or maybe I just looked at the problem from the wrong angle...
anyway, thanks in advance
- -- vbi
- --
Today is Prickle-Prickle, the 26th day of Discord in the YOLD 3172
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: get my key from http://fortytwo.ch/gpg/92082481
iKcEARECAGcFAkQ4zdRgGmh0dHA6Ly9mb3J0eXR3by5jaC9sZWdhbC9ncGcvZW1h aWwuMjAwMjA4MjI/dmVyc2lvbj0xLjUmbWQ1c3VtPTVkZmY4NjhkMTE4NDMyNzYw NzFiMjVlYjcwMDZkYTNlAAoJEIukMYvlp/fW834Anjg2J24MXgq/pitFzwHh9wPr 6q8NAKDCeA4etmeGEunQye/BAqQbj17n+w== =2/6v
-----END PGP SIGNATURE-----
Hash: SHA1
Yo!
Mostly as a finger-exercise (and because I'm annoyed again and again how bad the existing solutions are), I'm hacking up a web-based forum (yes, the 64832th one, I know).
I want to allow some simplified HTML as input language, and use some xsl to render that afterward. I do simple verification with a DTD (no problem in that), but the rendering into html is where I'm stuck currently.
The articles are stored as:
=====
<article>
<head>
<author>squiggle</author>
<title>Quack</title>
<date>2006-02-26 15:07:12</date>
</head>
<body>Says the Duck.</body>
</article>
=====
The body can be plain text, but mostly it should be simple HTML. I decided on the following feature set: <em>, <tt>, <p>, <a href="">, <img alt="" src=""> should be passed through unchanged. <title> should be changed to <h3>, and <blockquote cite="url"> should be changed to something like <div><blockquote cite="url">'the quote'</blockquote><div><a href="url">url</a></div></div>, if an URL is present, or only blockquote else.
The whole should be wrapped within some <div>'s, showing article title, author, date etc.
Now I've written some small piece of XSL:
=====
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl
<!-- title becomes h3 -->
<xsl:template match="title">
<h3><xsl:apply-templates/></h3>
</xsl:template>
<!-- blockquote gets visible citation -->
<xsl:template match="blockquote">
<xsl:element name="blockquote">
<xsl:attribute name="cite">
<xsl:value-of select="@cite"/>
</xsl:attribute>
<div class="text"><xsl:apply-templates/></div> <div class="cite"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@cite"/> </xsl:attribute> <xsl:value-of select="@cite"/> </xsl:element> </div> </xsl:element> </xsl:template>
<!-- a, em, img, p, tt go through unchanged -->
<xsl:template match="a|em|img|p|tt">
<xsl:copy>
<xsl:apply-templates select="@*|node"/>
</xsl:copy>
</xsl:template>
<!-- the complete head is stripped out -->
<xsl:template match="head">
</xsl:template>
</xsl:stylesheet>
=====
And I'm right now extracting article titles etc. manually from the perl code, and calling the xsl only on the body element. But this is not really what I want... The point where I'm stuck is with the rules which part of the xsl is called at which point on which part of the xml file. And also: I'll certainly need to filter the img and a tags, because I *only* want to allow the attributes I've talked about above. (OTOH this is already taken care of by the DTD, so maybe I just won't care.)
Pointers welcome, but most of the tutorials I've found so far stopped where things got really interesting. Or maybe I just looked at the problem from the wrong angle...
anyway, thanks in advance
- -- vbi
- --
Today is Prickle-Prickle, the 26th day of Discord in the YOLD 3172
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: get my key from http://fortytwo.ch/gpg/92082481
iKcEARECAGcFAkQ4zdRgGmh0dHA6Ly9mb3J0eXR3by5jaC9sZWdhbC9ncGcvZW1h aWwuMjAwMjA4MjI/dmVyc2lvbj0xLjUmbWQ1c3VtPTVkZmY4NjhkMTE4NDMyNzYw NzFiMjVlYjcwMDZkYTNlAAoJEIukMYvlp/fW834Anjg2J24MXgq/pitFzwHh9wPr 6q8NAKDCeA4etmeGEunQye/BAqQbj17n+w== =2/6v
-----END PGP SIGNATURE-----