xsl-list
[Top] [All Lists]

Re: [xsl] XSLT and XML in the same document

2007-05-29 03:37:11
On Tue, 29 May 2007 04:03:09 -0600, M. David Peterson <m(_dot_)david(_at_)xmlhacker(_dot_)com> wrote:

Ugg! There is oh so very much the browser can do with client-side XSLT that takes so much load off of the server.

Exhibit A: The following XSLT script interacts with an OpenID authentication service which takes a GET request -- e.g. http://example.com/service/gatekeeper/login?uname=http://mdp.openid.name&return_location=http://example.com/foobar -- contacts the OpenID server, determines where to send the client to be authenticated, and embeds that URI in an XML response that contains a PI pointing to this XSLT script. the XSLT script then redirects the client to the OpenID server, and upon determining if the request is authentic or not, the OpenID server will redirect the client back to the service that requested the authentication with a "thumbs up" or "thumbs down" response. The authentication service then puts that information into an XML message with the same PI, at which point the client-side XSLT determines where to redirect the client based on the information in the message.

One could easily look at this and suggest that the server should just do the redirects as sending messages to the client is an extra step that is unnecessary. Of course, if this was all the client-side XSLT solution did, you would most definitely be correct. However, when you add to the mix the ability to quickly and easily determine what content should be rendered on the client based on the response, you will (hopefully!) discover that *MUCH* power exists by passing nothing but simple XML messages around, and using these messages to then generate content on the client via XML and XSLT files that have long since been cached, accessing the proper data files via the document function for each specific page on any given site.

Of course, in doing so you also gain the benefit of bypassing the SGML parser and moving directly to the XML parser, which then means you are using the XSLT processor to transform the content directly into a DOM object. As such, no more quirks mode, no more SGML parser, no more junk clogging the internet pipelines that doesn't need to be sent to the browser -- *again* -- just because its the way things have been done in the past.

Heck, come to think of it, using client-side XSLT to both reduce processing as well as to reduce the amount of data being sent with each response could significantly reduce greenhouse gas emissions and save the planet as a result! ;-) :D

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns="http://www.w3.org/1999/xhtml"; xmlns:html="http://www.w3.org/1999/xhtml"; version="1.0"
    exclude-result-prefixes="html">

    <xsl:variable name="return-uri" select="/auth/return-location" />
    <xsl:variable name="vendor" select="system-property('xsl:vendor')" />

    <xsl:output doctype-system="-//W3C//DTD HTML 4.01//EN"
doctype-public="http://www.w3.org/TR/html4/strict.dtd"; cdata-section-elements="script"
        method="html" omit-xml-declaration="yes" />

    <xsl:template match="/">
        <xsl:apply-templates />
    </xsl:template>

    <xsl:template match="auth">
        <html xmlns="http://www.w3.org/1999/xhtml";>
            <head>
                <title>SonicRadar OpenID Redirection...</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
                <xsl:if test="@redirect-type = 'meta'">
                    <xsl:choose>
                        <xsl:when test="@status = 'redirect'">
<xsl:apply-templates select="url" mode="meta-redirect" />
                        </xsl:when>
                        <xsl:when test="@status = 'complete'">
<xsl:apply-templates select="message" mode="meta-redirect" />
                        </xsl:when>
                    </xsl:choose>
                </xsl:if>
                <xsl:if test="not(@redirect-type = 'meta')">
                    <script type="text/javascript">
                    <![CDATA[
                    var fs = new RegExp("%2F", "g");
                    var colon = new RegExp("%3A;", "g");
                    var amp = new RegExp("&amp;", "g");
                    function doRedirect(escapedURI){
window.location.replace(escapedURI.replace(fs, "/").replace(colon, ":").replace(amp, "&"));
                    };
                    ]]>
                    </script>
                </xsl:if>
            </head>
            <xsl:if test="not(@redirect-type = 'meta')">
                <xsl:choose>
                    <xsl:when test="@status = 'redirect'">
                        <xsl:apply-templates select="url" mode="replace" />
                    </xsl:when>
                    <xsl:when test="@status = 'complete'">
<xsl:apply-templates select="message" mode="replace" />
                    </xsl:when>
                </xsl:choose>
            </xsl:if>
        </html>
    </xsl:template>

    <xsl:template match="url" mode="replace">
        <body onload="doRedirect('{.}');">
            <h3>Redirecting...</h3>
        </body>
    </xsl:template>

    <xsl:template match="url" mode="meta-redirect">
        <meta http-equiv="Refresh" content="0;url={.}" />
    </xsl:template>

    <xsl:template match="message" mode="replace">
        <body
onload="doRedirect('{concat($return-uri, substring-before(substring-after(., 'http%3A%2F%2F'), '%2F'))}');">
            <h3>Redirecting...</h3>
        </body>
    </xsl:template>

    <xsl:template match="message" mode="meta-redirect">
        <meta http-equiv="Refresh"
content="0;url={concat($return-uri, substring-before(substring-after(., 'http%3A%2F%2F'), '%2F'))}"
         />
    </xsl:template>

</xsl:stylesheet>



--
/M:D

M. David Peterson
http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | http://dev.aol.com/blog/3155

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