xsl-list
[Top] [All Lists]

Re: dynamically extending xslt

2005-10-10 06:07:41
Hi Marco,

we are developing a new correspondence-system based on XML. Our DTD
is very similar to XHTML with some additional structures like
selections, iterations and variableplaceholders. The composition of
these documents will be realized as a XSLT-stylesheet. I wrote a
stylesheet wich transforms a document into a XSLT-stylesheet. This
(produced) stylesheet will be used on a XML-file containing the
variablevalues and the data needed to resolve the logical structures
(e.g. selections etc.).
[snip]
After this transformation the user is able to add another "topic" to
the document, which could contain another selection. And I need this
new content executed, after it is transformed into xslt.

I call the kinds of documents that you're using here "document
templates". Instead of doing:

                   your
                 stylesheet
                     |
                     v
  document  --> (transform) -->   XSLT
  template                     stylesheet
                                   |
                                   v
                      data --> (transform) --> final
                                               result


you might be able to get away with the slightly simpler process:

               your
             stylesheet
                 |
                 v
  data  --> (transform) --> final result
                 ^
                 |
              document
              template

In other words, use both the document template and the XML data as
inputs to the same stylesheet, and use them in conjunction to create
the final output that you're after.
              
Your stylesheet would contain something like:

<!-- Global variables for access to data and document template -->
<xsl:variable name="data" select="/" />
<xsl:variable name="template" select="document('template.xml')" />

<!-- Apply templates to the template to get the result -->
<xsl:template match="/">
  <xsl:apply-templates select="$template" />
</xsl:template>

<!-- Identity template to copy through everything by default -->
<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>

<!-- Templates to pick up on the "instructions" in your document
     template and use values from the data XML to resolve them -->
<xsl:template match="selection">
  <xsl:variable name="variable" select="@variable" />
  <xsl:variable name="value" select="$data//variable[(_at_)name = $variable]" />
  <xsl:apply-templates select="item[(_at_)value = $value]/node()" />
</xsl:template>

...

This way, people could edit and re-edit the document template without
having to worry about updating any stylesheets.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>