[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT and XML in the same document

Subject: Re: XSLT and XML in the same document
From: "M. David Peterson" <m.david@xxxxxxxxxxxxx>
Date: Tue, 29 May 2007 04:36:52 -0600
Re:  XSLT and XML in the same document
On Tue, 29 May 2007 04:03:09 -0600, M. David Peterson
<m.david@xxxxxxxxxxxxx> 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&retu rn_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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.