This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: variable and match
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: variable and match
- From: Kevin Williams <Kevin dot Williams at ultraprise dot com>
- Date: Fri, 12 May 2000 11:20:45 -0400
- Reply-To: xsl-list at mulberrytech dot com
One way I've done this is to use a two-step process; first, create your
"dynamic" stylesheet by transforming your original XML into XSLT; then,
apply the newly-created stylesheet to the original XML to produce your
output. For your example, if you take the following "meta" stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/ROWSET">
<xsl:element name="xsl:stylesheet">
<xsl:attribute name="version">1.0</xsl:attribute>
<xsl:element name="xsl:template">
<xsl:attribute name="match">/ROWSET/<xsl:value-of
select="REPLACE/@EL"/>
</xsl:attribute>
<xsl:element name="xsl:element">
<xsl:attribute name="name">ROWSET</xsl:attribute>
<xsl:element name="xsl:element">
<xsl:attribute name="name">NEWELEMENT</xsl:attribute>
<xsl:element name="xsl:copy-of">
<xsl:attribute name="select">*</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
And use it to transform
<ROWSET>
<REPLACE EL="FOO"/>
<FOO>
<DATA1>data1</DATA1>
<DATA1>data1</DATA1>
</FOO>
</ROWSET>
The output is:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ROWSET/FOO">
<xsl:element name="ROWSET">
<xsl:element name="NEWELEMENT">
<xsl:copy-of select="*"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Using this output to style the original XML yields:
<ROWSET>
<NEWELEMENT>
<DATA1>data1</DATA1>
<DATA1>data1</DATA1>
</NEWELEMENT>
</ROWSET>
A little cumbersome, perhaps, but it works for the example you give...
- Kevin
Kevin Williams
XML Architect, Ultraprise Corporation
> -----Original Message-----
> From: Ross Cormier [mailto:merex@home.com]
> Sent: Friday, May 12, 2000 8:35 AM
> To: xsl-list@mulberrytech.com
> Subject: RE: variable and match
>
>
> OK, then how can I dynamically create a template in XSLT?
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list