RE: [xsl] hard core xlt ;-)

Subject: RE: [xsl] hard core xlt ;-)
From: "Dylan Walsh" <Dylan.Walsh@xxxxxxxxxx>
Date: Thu, 26 Jul 2001 16:40:34 +0100
>could you post an code example of an XSLT that generates an XSLT?

I've stripped out all the stuff that is specific to our companies
product so what is left is a transformation that does nothing, but does
serve as an intro to XSLT generation.
The way I'm using namespaces below is designed so that the output XSLT
uses the popular "xsl" namespace prefix, or atleast does so when used
with JAXP1.1/Xalan2.

<?xml version="1.0"?>
<!--
SNIP

Understanding this XSLT:
A point to note is that XSL transformations, that create XSL
transformations, must use two namespaces 
and namespace-alias to distinguish the XSL elements *in the output*,
from those XSL elements 
used to *create* the output. The XSL instructions that the processor,
processing this file, will
act on are in a namespace prefixed with "xsl2"

Dylan Walsh
-->

<xsl2:stylesheet version="1.0" 
	xmlns:xsl="Dummy namespace for the output XSL"
	xmlns:xsl2="http://www.w3.org/1999/XSL/Transform";> 

  <xsl2:output method="xml" indent="yes" />

  <!-- 
  This instruction causes the XSL elements we want to *generate*, which,
in this
  document, are distinguised by being in a dummy namespace (prefixed
here by 'xsl'),
  to be placed in the XSL namespace (prefixed here by 'xsl2') in the
output.

  So elements prefixed by 'xsl2' are the XSL instructions in this sheet,
and elements prefixed by
  'xsl' are literals - the output that will be generated. 
  -->
  <xsl2:namespace-alias stylesheet-prefix="xsl" result-prefix="xsl2" />

  <xsl2:template match="/">
    <xsl:stylesheet version="1.0"> 
      <!-- SNIP. What goes here is up to you. -->
    </xsl:stylesheet>
  </xsl2:template>
</xsl2:stylesheet>

> -----Original Message-----
> From:	Joost Fleuren [SMTP:joost@xxxxxxxxxxx]
> Sent:	Thursday, July 26, 2001 2:28 PM
> To:	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:	RE: [xsl] hard core xlt ;-)
> 
> Hi Dylan,
> 
> could you post an code example of an XSLT that generates an XSLT?
> I could use an example.
> 
> Kind regards,
> Joost Fleuren.
> 
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Dylan
> Walsh
> > Sent: Thursday, July 26, 2001 1:32 PM
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Cc: Elise D.
> > Subject: RE: [xsl] hard core xlt ;-)
> > 
> > 
> > Here are some comments what I consider to be two of the
> harder/hardest
> > things to do in XSLT:
> > 
> > 1. "Generic" XSLT. Usually you write a stylesheet with assumptions
> about
> > the structure of the input XML. Generic XSLT makes no such
> assumptions.
> > It processes the source in terms of node types. An element contains
> > other elements, attributes, text, comments, etc. Start at the root
> node
> > and drill down, using recursion (e.g. element template calls
> > apply-templates on its subelements).
> > A few months after starting to learn XSLT, I created two stylesheets
> > using this approach. One of them takes any XML and creates a
> > colour-coded and indented HTML "pretty print" of the XML. You could
> use
> > it to present itself. The other stylesheet took created a specimen
> of
> > XML and generated a first-cut DTD. 
> > I had to ask a lot of questions on this list, but I learned an
> enormous
> > amount about XSLT.
> > 
> > 2. XSLT that generates XSLT. The issue here is that you have two
> > namespaces for the XSLT, one for the actual instructions in the
> > stylesheet, and one for the XSLT you will be generating. It is not
> > always difficult, depending on how much variation there is in the
> output
> > stylesheet. The tricky thing is that you are effectively writing two
> > transformations at the same time, each applying to different source
> XML,
> > and you have to think about e.g. which transformation should make a
> > given decision.
> > 
> > Both of these are great lessons in XSLT. There are others
> > - simulating "looping" using recursion  
> > - the misc. sorting issues and the Muenchian method (will be
> obsolete in
> > XSLT 2.0?)
> > 
> > and I'm sure people can add to that list. Possibly the final step
> would
> > be to implement XSLT yourself, but you don't have to build cars to
> be a
> > good driver.
> > 
> >  XSL-List info and archive:
> http://www.mulberrytech.com/xsl/xsl-list
> > 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

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


Current Thread