[XML-SIG] xsl:nclude-and-transform
Uche Ogbuji
uche.ogbuji@fourthought.com
Wed, 18 Jul 2001 10:25:40 -0600
> Hi Lists,
> =
> Here is what I'd like to do :
> =
> company.xml (my own DTD)
> =
> <company>
> <name>Logilab</name>
> <address>10 rue Louis Vicat</address>
> <web>http://www.logilab.com/</web>
> </company>
> =
> document.xml (DocBook DTD)
> =
> <article>
> <author>
> <surname>Chauvat</surname>
> <affiliation>
> <!-- insert here the result of company.xml
> transformed with company2docbook.xsl
> should be
> =
> <orgname>Logilab</orgname>
> <address>
> <street>10 rue Louis Vicat</street>
> </address>
> -->
> </affiliation>
> </author>
> =
> <sect>
> <!-- the rest of my document -->
> </sect>
> </article>
> =
> Here are the ideas I had so far :
> =
> * forget about my own DTD and write company.xml using docbook, the=
n
> include an entity. It already works like this, but I need to
> make it more flexible...
> =
> * generate the document in two steps : replace the above comment w=
ith
> a specific <include file=3D"company.xml/> tag that gets processe=
d by
> a first XSLT and replaced with the proper docbook elements, then=
> feed the result to the docbook generator. The problem is that wh=
en
> you generate a document, you have to know which stylesheet to ap=
ply
> for the first processing step.
> =
> * generate the document in a single step : modify the above tag to=
> specify the stylesheet : =
> <include file=3D"company.xml" transform=3D"company2docbook.xsl=
"/>
> and use something like an XSL extension function to replace that=
> include tag with the corresponding elements. That would ask for
> docbook XSL customization, but we already do that.
> =
> * use processing instructions : I don't know much about PI. Could
> I use a PI to do the two-step processing described above by
> including a <?PI use-stylesheet=3D'first-step.xsl'?> in the docu=
ment
> that I feed to the docbook processing step ?
> =
> * ...
> =
> As you understood, I'm missing a <xsl:include-after-transform/> tag...
> =
> I look forward to your ideas and comments.
For max flexibility I'm guessing you wan thtis to be transparent to the =
stylesheet. The best way I could think of makinng this happen would be t=
o add =
an option to the 4XSLT processor for translating xinclude instructions fr=
om =
result elements.
This would take the form:
* Update the XmlWriter and RtfWriter to look out for output requests that=
meet =
XInclude spec and automatically render the resulting text or nodes into t=
he =
output. Probably by parsing to cDomlette in both cases, and calling =
xml.dom.ext.Print on the resulting document element in the case of XMLWri=
ter =
(watch out for cdata-section-element specs and CDATASections in the XIncl=
uded =
file). In the case of RTFWriter, one could either translate the domlette=
=
nodes to RTFNodes or just write a quick'n dirty writer that generates RTF=
Nodes =
directly from text.
* Add a parameter to the processor (off by default) which enables this =
automatic translation
This actually would not be that difficult to implement, and if you're itc=
hing =
badly enough, you might want to work out a patch (on the R0-11-1-prerelea=
se =
branch of CVS 4Suite) that implements it. It's useful enough (and an ine=
rt =
enough feature) that if all goes well, it could be included in 0.11.1 fin=
al, =
even though bugfixes are the priority at this point.
Failing that, and if you don't mind minimal XSLT additions, the best solu=
tion =
is probably
<xsl:template match=3D"affiliation">
<xsl:variable name=3D"included">
<xsl:value-of select=3D"document('company.xml')"/>
</xsl:variable>
<xsl:copy>
<xsl:copy-of select=3D"$included"/>
</xsl:copy>
</xsl:template>
Does all this help?
-- =
Uche Ogbuji Principal Consultant
uche.ogbuji@fourthought.com +1 303 583 9900 x 101
Fourthought, Inc. http://Fourthought.com =
4735 East Walnut St, Boulder, CO 80301-2537, USA
XML strategy, XML tools (http://4Suite.org), knowledge management