[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XSLT template from XSLT + XML


Subject: Re: [xsl] XSLT template from XSLT + XML
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 30 Sep 2002 21:20:10 +0100

Hi Michael,

> I am trying to take an XML file and an XSL file, transform them
> using MSXML 3.0, and output an XSL. I have two files that I've
> gotten this to work for by liberally using the xsl:element and
> xsl:attributes.
>
> The first two worked fine, I did them pretty much by hand, there
> weren't too many templates to create via xsl:element
> name="xsl:template".

I guess that you haven't discovered the delights of
xsl:namespace-alias, then. You can define an "alias" namespace which
takes the place of the XSLT namespace within your stylesheet and then
gets replaced on output. That makes it a lot easier to write the
stylesheets (though it's still a little confusing) because you can use
literal result elements rather than xsl:element/xsl:attribute.

For example, in this stylesheet 'xsl' is the prefix for XSLT
instructions to be interpreted in the stylesheet, whereas elements
without a prefix are elements to be added to the result:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/1999/XSL/TransformAlias">

<xsl:namespace-alias stylesheet-prefix="#default"
                     result-prefix="xsl" />

<xsl:template match="/">
  <stylesheet version="1.0">
    <output method="html" />
    <xsl:apply-templates />
  </stylesheet>
</xsl:template>

<xsl:template match="foo">
  <template match="{@bar}">
    ...
  </template>
</xsl:template>

</xsl:stylesheet>

> Reading this over, its difficult to accurately convey what I'm
> trying to do, much less the why. I guess what I'm wondering is, can
> I create an xsl template (a) to read in one xsl template (b) and
> output a template (c), which when combined with an xml file (x)
> containing some options, output a template (d) very similar in
> structure to template b. Then I can tweak template c to make use of
> the options in file x. Whew.

Perhaps you could give an example?

Cheers,

Jeni

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


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords