Re: [xsl] Generating an XSL from an XML

Subject: Re: [xsl] Generating an XSL from an XML
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 14 May 2002 15:13:25 +0100
Hi Rémy,

> i would like to know if there won't be any problems using an XSL
> stylesheet to generate another stylesheet.
> For example, i wanted to use an xml defining a format, and generate
> the default xsl stylesheet able to parse an xml using that format
> into a text file.
> I was inquisitive to know whether there were another option than
> using a <![CDATA section for every XSL instruction i wanted to
> generate, so that the parser didn't try to execute them.

Absolutely. This is the role of the xsl:namespace-alias element. The
xsl:namespace-alias element allows you to put all the instructions
that you want to generate in a different namespace (whatever you
like), so that they're not treated as XSLT instructions, and then
automatically move them into the XSLT namespace in the result tree, so
that they end up being XSLT instructions.

To use it, you define the alias namespace in the document element
(here I'm using the default namespace as the alias namespace):

<xsl:stylesheet version="1.0"

The xsl:namespace-alias element is a top-level element, with two
attributes: stylesheet-prefix, which specifies the prefix of the alias
namespace in the stylesheet; and result-prefix, which specifies the
prefix of the namespace that elements in that namespace should be
placed in within the result tree. You can use #default to indicate the
default namespace (no prefix) in either attribute:

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

Then you can just use literal result elements to create the XSLT
instructions. For example:

<xsl:template match="foo">
  <xsl:for-each select="bar">
    <value-of select="{@xpath}" />

creates an xsl:value-of instruction for each bar element, whose select
attribute has the value of the xpath attribute on the bar element.

The other method is to use xsl:element/xsl:attribute, but using a
namespace alias is a lot easier if you're needing to create a lot of



Jeni Tennison

 XSL-List info and archive:

Current Thread