cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrzej Jan Taramina" <andr...@chaeron.com>
Subject Re: Ways to implement Dynamic XSLT in Cocoon
Date Thu, 20 Jan 2005 14:53:32 GMT
Matt:

> Has anyone come across or written an transformer-based way to dynamically
> modify an XSLT template at processing time?
> 
> My challenge is this:
> 
> To facilitate Web Metric analysis, we need to embed vendor-supplied JAVA
> script in each page.  This JAVA script (and/or vendor) may change over time,
> and I want to maintain separation of concerns such that the business (as
> opposed to the Cocoon Development Team) can make changes to the vendor and/or
> JAVA script content without requiring changes to the site coding.
> 
> The JAVA script is very dynamic and may include page-specific code that makes
> use of data embedded in the page, as well as common variables.  In short, we
> cannot include the script in the XSLT directly because of it's dynamic nature
> and the lack of XSLT knowledge in the business.

I've done this in an application I designed and wrote.  The HTML page 
returned to a user is generated by a transform, since it's based on an XML 
input document.  The javascript that is used by this page is also generated 
dynamically based on that same XML input.

> I would like to implement a strategy whereby the script for the entire site is
> encapsulated in an XML file for each Web Metrics vendor, and a transformer
> uses this XML, coupled with a Page ID to add a template to the XSLT stylesheet
> instance being transformed by the Xalan SAX Parser at build time.  The page
> data to insert will be represented as XPaths embedded within the extra XSLT
> template.
> 
> My investigations show that a good approach would be to make a copy of the
> TraxTransformer and intercept the XSLT data before it is actually transformed,
> adding the template (which has been added to the pipeline SAX events by my new
> WebMetricsTransformer), and then passing a StringReader containing the new
> XSLT Source object into the transform.

This sounds overly complex to me.

Why not take the approach I used, which was to create a separate pipeline 
that outputs the customized javascript, looking something like the following:

<map:pipeline>
	<map:match pattern="customJavascript.js">
		<map:generate src="{request-param:pageID}-{request-param:vendor}-
jsdefinition.xml"/>
		<map:transform src="createJavascript.xsl">
			<map:parameter name="pageID value="{request-param:pageID}"/>
			<map:parameter name="vendor" value="{request-param:vendor}"/>
		</map:transform>
		<map:serialize type="text"/>
	</map:match>
<map:pipeline>

In this example, there are two request parameters passed in, pageID and 
vendor. The encapsulated script is found in files that look like pageid-
vendor-jsdefinition.xml and you have a simple xsl called createJavascript.xsl 
which extracts the javascript from the xml def, potentially modifies it using 
the passed in parms and returns pure .js.

Then in the xsl transform that is creating the actual HTML page for the user 
you just do something like this, at the point where you want to embed the 
custom javascript:

	<xsl:variable name="scriptURL" 
		select="concat( 'cocoon:/customJavascript.js?pageID=', $pageID, '&vendor', 
$vendor )"/>

	<xsl:copy-of select="document( $scriptURL )"/>

That seems a lot simpler than your approach.


Andrzej Jan Taramina
Chaeron Corporation: Enterprise System Solutions
http://www.chaeron.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message