This project is read-only.

Mission impossible: dynamic import?

Mar 11, 2011 at 9:16 AM


I'm performing some tests with the inclusion of other xslt, by xsl:import or xsl:include: I am able to include external xslt this way, but now... I want more :-)

What I'm not sure is possible now is including mdo templates this way, and of course having them work. Would this be possible?

Imagine I have the following xslt: my questions are...

  • can I include it in a xsltdb module (by xsl:include or import), and have the main xslt (the importer, applying the external xslt by call-template) see mdo special templates (for example the callable js function here)?
  • could I dynamically include external xslt (without knowing at designe-time what xsl(s) to include)?

I'll also try using the new host control soon, but would it be possible to use it inside an xsltdb module? I mean an xsltdb module instancing another configuration. And again, would this allow to include secondary templates (mdo:service, callable etc) too?


included xslt:

<xsl:stylesheet version="2.0"
   exclude-result-prefixes="msxsl mdo"
    <mdo:callable js="Sgrunt()" type="text/html">
        <xsl:template match="/">
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
    <xsl:param name="customParam"/>
   	<xsl:template match="/" name="testplugin2">
        <script type="text/javascript">
            function test1()
            var s = Sgrunt();
        Hello Sgrunt Test: <a onclick="javascript:test1();">CLick Sgrunt test1</a>

Mar 12, 2011 at 10:11 AM
Edited Mar 12, 2011 at 10:50 AM


1. referencing one XsltDb from another.

Tags like <mdo:*/> are not processed by XSLT processor. Those tags are used to split configuration in independent parts that can be executed separately. And then XSLT processor is executed.

As you noticed you can put XsltDb module as a user control inside another XsltDb module. In this case you will be able to use imported mdo:callable-s. But other stuff (mdo:service-s, mdo:template-s, mdo:importable-s etc.). won't work I think...

Actually, I must provide a way to explicitly reference configuration with out non-xslt tag like <mdo:import src="some other configuration"/>. But at the moment I have no such option.

2. Importing XSL dynamically.

You can't import external xsl on-the-fly, tis is an XSLT limitation. But you can execute any xsl on-the-fly with mdo:transform(xml, xsl), or mdo:xsltdb(alias) extensions


<xsl:variable name="xsl"><![CDATA[
  <xsl:value-of select="'I am from external xsl 123'"/>

{h{mdo:transform('&lt;root/&gt;', $xsl)}}

But at the moment these functions add some XsltDb-related extra output you probably don't want... I'll fix this in next release.