Templating vs XML + XSL?

Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here.
Forum rules
Discuss features as they are added to the new version. Give us your feedback. Don't post bug reports, feature requests, support questions or suggestions here. Feature requests are closed.
Post Reply
User avatar
pc-tutorials
Posts: 27
Joined: Mon Aug 14, 2006 6:47 am
Location: Steenbergen, The Netherlands
Contact:

Templating vs XML + XSL?

Post by pc-tutorials » Wed May 16, 2007 3:57 pm

I know, it sounds like some kind feature request, but I want to know: "What do you think of XML + XSL instead of the current template system?" I think that would have some major advantages, for example easier integration with other applications and easier templating. When you build such a system there are 2 options: make an template that generates XML and use XSL, or generate XML right out of the PHP pages. Which is the best? What are the advantages? Is it possible?

Thanks in advance!
for($i=1;$i>0;$i++){
echo "Bug detected, fix in progress";
}
----------------
Sorry for bad English, I'm not native :)

User avatar
SHS`
Registered User
Posts: 1628
Joined: Wed Jul 04, 2001 9:13 am
Location: The Boonies, Hong Kong
Contact:

Re: Templating vs XML + XSL?

Post by SHS` » Wed May 16, 2007 4:19 pm

Aside from the fact until PHP5.whateveritwas that bundled libxml2, XSL support in PHP was really rather poor, XSL itself has a rather whacky syntax and the fact you need to figure out XPath (bit like SQL for XML :P)... even a simple XSL for transforming Atom or RSS2 into XHTML is quite "eep":

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!-- DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#160;" >
<!ENTITY laquo "&#171;" >
<!ENTITY raquo "&#187;" >
] -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:atom="http://www.w3.org/2005/Atom">
<xsl:output method="html"></xsl:output>
<xsl:output indent="no" method="html"/>
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>
<xsl:output doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />
<xsl:template match="/">
<xsl:variable name="feedtype">
<xsl:if test="atom:feed"><a href="http://atompub.org/2005/08/17/draft-ietf-atompub-format-11.html" title="AtomPub.org: Atom Syndication Format">Atom 1.0</a></xsl:if>
<xsl:if test="rss"><abbr title="Really Simple Syndication/RDF Site Summary" class="initialism">RSS</abbr><xsl:text> </xsl:text><xsl:value-of select="/rss/@version" /></xsl:if>
</xsl:variable>
<xsl:variable name="itemscount" select="count(/atom:feed/atom:entry|/rss/channel/item)" />
<xsl:variable name="feedtitle" select="/atom:feed/atom:title|/rss/channel/title" />

<xsl:variable name="feedselflink" select="/atom:feed/atom:link[@rel='self'][@type='application/atom+xml']/@href|/rss/channel/link" />
<xsl:variable name="feedpagelink" select="/atom:feed/atom:link[@rel='alternate'][@type='application/xhtml+xml']/@href|/rss/channel/link" />
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr">
<head>
<!-- blah blah blah pretty XHTML stuffage -->
        <xsl:if test="$itemscount > 0">
        <p>The last <xsl:value-of select="$itemscount" /> item<xsl:if test="$itemscount > 1">s</xsl:if> on the <xsl:copy-of select="$feedtype" /> feed for &#8216;<a href="{$feedpagelink}" title="{$feedtitle}"><xsl:value-of select="$feedtitle" /></a>&#8217; <xsl:if test="$itemscount = 1">is</xsl:if><xsl:if test="$itemscount > 1">are</xsl:if>:</p>

        <dl id="rssItems">
        <xsl:for-each select="/atom:feed/atom:entry|/rss/channel/item">
        <dt>
            <a href="{atom:link[@rel='alternate']/@href|link}">
            <xsl:value-of select="atom:title/xhtml:div|title" /></a>
        </dt>
        <dd>
        <ul>
            <li class="blurb"><xsl:value-of select="atom:summary/xhtml:div|description" disable-output-escaping="yes"/></li>

            <xsl:if test="atom:published|pubDate">
            <li class="date">Posted on: <xsl:value-of select="atom:published|pubDate" /></li></xsl:if>
        </ul>
        </dd>
        </xsl:for-each>
        </dl>
        </xsl:if>
        <xsl:if test="$itemscount = 0">

        <p>There's bugger all in this <xsl:copy-of select="$feedtype" /> feed for &#8216;<a href="{$feedpagelink}" title="{$feedtitle}"><xsl:value-of select="$feedtitle" /></a>&#8217;! :(</p>
        </xsl:if>
<!-- rest of the XHTML stuffage -->
</html>

</xsl:template>
</xsl:stylesheet>
(Atom/RSS2/RSS1)+XSL sexay:
xslt-sexay.png
(Atom/RSS2/RSS1)+XSL sexay
(220.96 KiB) Downloaded 2829 times
Jonathan “SHS`” Stanley • 史德信
phpBB™ 3.1.x, Bug/Security trackers
phpBB™ Bertie Bear 3.0 — prosilver Edition!Asking Questions The Smart Way

User avatar
VinDuv
Registered User
Posts: 73
Joined: Wed May 03, 2006 8:10 pm
Location: France
Contact:

Re: Templating vs XML + XSL?

Post by VinDuv » Wed May 16, 2007 5:10 pm

And it seems that XML-XSL browser support is not very good at this time. For example, when I open a modX file (phpBB MOD written in XML with an XSL stylesheet) in Safari, I can't use keyboard shortcuts anymore 8O (And ⌘C - ⌘V is very useful when you want to apply a MOD...).

User avatar
pc-tutorials
Posts: 27
Joined: Mon Aug 14, 2006 6:47 am
Location: Steenbergen, The Netherlands
Contact:

Re: Templating vs XML + XSL?

Post by pc-tutorials » Wed May 16, 2007 5:21 pm

SHS` wrote: Aside from the fact until PHP5.whateveritwas that bundled libxml2, XSL support in PHP was really rather poor, XSL itself has a rather whacky syntax and the fact you need to figure out XPath (bit like SQL for XML :P)... even a simple XSL for transforming Atom or RSS2 into XHTML is quite "eep":

I think it isn't that hard. I have some experience in using XSL with style sheets, but they got never so long 8O And about that XSL support in PHP: why should you need that? Templating with XSL in on client level, isn't it?
VinDuv wrote: in Safari, I can't use keyboard shortcuts anymore 8O (And ⌘C - ⌘V is very useful when you want to apply a MOD...).

......
Ok, that's weird :)
for($i=1;$i>0;$i++){
echo "Bug detected, fix in progress";
}
----------------
Sorry for bad English, I'm not native :)

User avatar
SHS`
Registered User
Posts: 1628
Joined: Wed Jul 04, 2001 9:13 am
Location: The Boonies, Hong Kong
Contact:

Re: Templating vs XML + XSL?

Post by SHS` » Wed May 16, 2007 10:07 pm

pc-tutorials wrote: I think it isn't that hard. I have some experience in using XSL with style sheets, but they got never so long 8O And about that XSL support in PHP: why should you need that? Templating with XSL in on client level, isn't it?


To do a web application that uses XSL client-side is akin to suicide. If you are thinking of trying to be "clever" and have XML sent to a browser which gets client-side XSLT'ed to HTML... fine, that mostly works. XSLT'ed to an Atom or RSS feed will not work, as none of the popular news readers support XSLT (generally seen as browser "fluff", so often gets disabled/removed).
Jonathan “SHS`” Stanley • 史德信
phpBB™ 3.1.x, Bug/Security trackers
phpBB™ Bertie Bear 3.0 — prosilver Edition!Asking Questions The Smart Way

Whalemart
Registered User
Posts: 2
Joined: Tue May 15, 2007 5:44 am

Re: Templating vs XML + XSL?

Post by Whalemart » Sat May 19, 2007 8:31 am

http://armory.worldofwarcraft.com/chara ... ade&n=Ming

It's built entirely upon an XML transformation. Instead of using server power to transform {VAR} to a registered array value you could just output all the registered values into a neat XML doc and use the clients machine to transform it using an XSL 'template' document.

At least that's my understanding of the subject. How easy it would be to learn to template seeing as one would need to learn the XML/XSL syntax and such I don't know.

User avatar
{o}
Registered User
Posts: 90
Joined: Wed Mar 31, 2004 1:26 pm
Contact:

Re: Templating vs XML + XSL?

Post by {o} » Sun Feb 10, 2008 6:10 pm

SHS` wrote:even a simple XSL for transforming Atom or RSS2 into XHTML is quite "eep":
Hey, this code is so cluttered because its idea is cluttered. It tries to transform from two, different file formats in only one template - this is not simple. The obvious way of getting this done is to make 2 separate templates...

Using XSLT as templating engine wouldn't be so intricate. Just replace

Code: Select all

<!-- BEGIN foo -->
with

Code: Select all

<x:template match="foo">
Due to recurrent, functional nature of XSLT, in many cases you can even reduce the complexity of templates by splitting them into smaller, reusable ones. Componentization is possible.

But even if you still claim XSLT is hard to learn or use - this standard is widely supported by many development environments, giving you ability to make templates easily. Even in WYSIWYG mode. Can you say so about phpBB's native templating syntax? Is it supported by whaterer?

Next adventage is security. HTML injection, XSS? No way.
Also - language packs would be just XML files, not dangerous PHP code.

You can't produce mal-formed output.
If client supports XSLT, processing transformation can be delegated to him, reducing server load.

The only one real disadventage I can see is performance of generating input. It must be DOM, which is probably slower than PHP associative arrays :)

Post Reply