Altova Mailing List Archives

Re: [xsl] Generating an XSL from an XML

From: Jeni Tennison <jeni@---------------->
Date: 5/14/2002 6:24:00 AM
Hi R&eacute;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:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.