[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] xsl:apply-templates in javascript


Subject: Re: [xsl] xsl:apply-templates in javascript
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 25 May 2005 11:32:09 -0400

Brandon,

Is it really necessary to load part of your document dynamically? (I'd consider the simpler solution of simply hiding the content and exposing it dynamically, if I could.)

If so, you might ask that question -- how do I load part of a document dynamically -- in whatever scripting forum is appropriate. (I don't know what kinds of constraints over your scripting you face: e.g. must this be multi-platform. But those aren't XSLT questions.)

In general, your question is difficult because two different paradigms of document processing are colliding. In general, the Javascript method of "tag-writing" output back to the browser is inimical to (though as you have supposed, not impossible in) XSLT, where we prefer to serialize whole document trees, not just fragments at a time (thus it's an architectural question). Fortunately, these days one has the DOM, and the browsers support methods for working with sets of nodes (elements and attributes) rather than writing tags. I'd try writing my Javascript to use such methods, rather than doing tag writing.

But none of that is really pertinent to XSLT. To answer the question as given: you can "tag write" HTML if you want to (just as you can "tag write" a representation of the XML source), using disable-output-escaping. It would be a terrible shame, but it could be done.

I have my doubts that the resulting Javascript would be either as robust or as portable as Javascript DOM methods, however.

Cheers,
Wendell

At 09:19 PM 5/24/2005, you wrote:
I know, this has been solved, but what I'm looking for is an easy way to transition into it.

I want to
document.write('<xsl:apply-templates select=3D3D"path/to/node" />');

But obviously XSL will create a node set. I know the correct method is to escape the < characters with &lt;, but how can you implement this properly with a template? I've read of the "serialise" method that will apply a template that puts &lt; between <xsl:text /> tags and recursively calls the template. But that won't actually give me the html. How can I (without actually rewriting all my templates) escape and insert the html into the javascript.

Or maybe there's a better way to dynamically load a section of the document, which I would like.


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


Current Thread
Keywords