Re: [xslt] data callbacks?




On Oct 21, 2008, at 11:37 AM, Paul Miller wrote:

Just came across libxslt and it's brilliant (and fast!). I was thinking about embedding it into an app as a report generator and I think what I want to do is possible, but I wanted to double-check here first.

I'd like to write some XML that describes a report - basic layout information plus what columns/rows of data to output. But there is no actual data in this XML - the data needs to be generated on the fly within my application. I'd like to stick some custom elements or attributes that cause libxslt to call back into my application using a callback function and replace that element with possibly more elements with specific text nodes.

For example, let's say I have an element like this:

  <data id="income" range="5"/>

In my template, I'd like to convert this to something like this in the resulting XML:

  <data>100.00</data>
  <data>200.00</data>
  <data>300.00</data>
  <data>400.00</data>
  <data>500.00</data>

So what I'd like to happen is for the xslt to see the "range" and "id" attributes and then call back into my code with information about this element. Then I'd like my code to replace this element with its own set of elements, filling in the data values as it goes.

Is this possible? Is this a good idea? Any suggestions on what API to use to handle this?


You could use the document function. Perhaps target a script like:

<xsl:apply-templates
select="document(concat('path/to/script?id=', @id, '&amp;range=', @range))"/>

You would need to return a well-formed document (your data elems wrapped in a root elem), I believe.

best,
-Rob



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]