cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Lundquist ...@wrinkledog.com>
Subject Re: Ways to implement Dynamic XSLT in Cocoon
Date Thu, 20 Jan 2005 05:11:34 GMT

On Jan 19, 2005, at 7:48 PM, Matt Robinson wrote:

> Hello.
>
> Has anyone come across or written an transformer-based way to 
> dynamically modify an XSLT template at processing time?

The "normal" way to do that would be to process your "first order" 
stylesheet through a "second-order" stylesheet, and use the "cocoon:" 
pseudoprotocol to invoke the pipeline that does this, e.g.

	<generate src="some-XML"/>
	<transform src="cocoon:/get-stylesheet" />

But I'm not sure it even has to be that involved...

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

Why not

	<script language="javascript" src="Metrics.js" />

???

I can't imagine why the JS would have to be inline, but if it did, you 
could

(a) interpolate it using the Xinclude or Cinclude transformer; or,
(b) interpolate it using the Xpath document() function (note, the URI 
can use the "cocoon:" scheme); or,
(c) use map:aggregate to get it into the same source stream, and merge 
it in in your stylesheet

All of those are standard Cocoon techniques that don't require any 
custom componentry.  It seems like you're wrapped around the axle of 
"must get JS into the stylesheet", and while there's an easy way to do 
that (see the very beginning of this post), but if all you need to do 
is get some content into your final output, there are plenty of simpler 
ways to do that.  Or maybe I'm just not understanding your problem 
correctly?

cheers,
—ml—


Mime
View raw message