Updated 2012-09-10 15:00:55 by LkpPo

XSLT = XSL Transformations.

The specification can be found at http://www.w3.org/TR/xslt

[Explain what XSLT is.] [Point to http://phaseit.net/claird/comp.text.xml/XSLT.html also.]

LES: One of the links in Cameron's page, "Using tDOM and tDOM XSLT", is broken. That same link is mentioned at tDOM's home page: [1]. Now, I wonder if anyone still has that article...

The March 2002 Linux Journal [2] leads off with an introduction to XSLT [3] which features tDOM.

Two implementations are already in industrial production. Zveno's TclXSLT .... Early in development, Zveno also wrapped James Clark's XSL processor with TclBlend (!). This is now obsolete. Zveno's standard TclXSLT, like its TclXML, comes in both pure-Tcl and compiled-with-C flavors.

Steve Ball: No, that's not true. TclXSLT is a wrapper for libxslt and does not have a pure-Tcl implementation.

Jochen Loewer's tDOM includes XSLT (and XPath!) capabilities which make it the fastest raw engine available, better even than any of the commercial Java offerings.

Neil Madden, aware of the existing XSLT implementations, is considering wrapping (Apache's) Xalan or even coding a subset of XSLT in pure Tcl.

NEM - I've given up on this as I managed to compile tDOM with XSLT support for the platforms I need.

Which platforms? I've been searching for an XSLT engine that would do some simple transforms on Linux, MacOS 8.1, and Win32. I've compiled TclXSLT on Win32, but can't get it to do any transforms without crashing. That's about as far as I've gotten. My plan was going to involve just calling xsltproc as an external process on Win32 and Linux, and disabling the XSLT-related parts of the Mac version of my program. But if tDOM works on MacOS, then I can use that instead. Which tDOM binaries have you successfully compiled and built? --unDees

Would Graphlet [4] make for a nice XSLT front end? What are the other Graph editors?

AK I do not believe so, at least not at first glance. At its core XSLT is a tree transformation language.

[Recommend Mike Kay's XSLT Programmer's Reference.] RS has been reading his paper "What kind of language is XSLT?". Some quotes: "Although XSLT is based on functional programming ideas, it is not yet a full functional programming language, as it lacks the ability to treat functions as first-class data type." - "The XSLT language allows variables to be defined, but does not allow an existing variable to change its value - there is no assignment statement." Some code snippets compared, just to give an impression. First Tcl:
 variable foo 42
 $foo ;# in some output context
 foreach i $list {...}

 <xsl:variable name="foo" select="42"/>
 <xsl:value-of select="$foo"/>

 <xsl:for-each select="$list"/>
 ... <!-- iterator value can be retrieved as select="." -->

Apart from $, @ may also prefix a variable name - possibly scalar/array distinction as in Perl?

Steve Ball: @ references an attribute value. It does not dereference a variable. Only $ does that.

Another example: a function to format a number left-justified fixed-width:
 <xsl:template name="formatNum">
 <xsl:param name="number"/>
 <xsl:value-of select="concat($number,
       substring('       ',1,5-string-length($number)))"/>

It's called like this:
 <xsl:variable name="fstring">
    <xsl:call-template name="formatNum">
        <xsl:with-param name="number"><xsl:value-of select="@cred"/>

The whole stuff above roughly amounts to Tcl's
 proc formatNum number {format %-5d $number}
 set fstring [formatNum $cred]

Another intriguing code base for XSLT processing is the Sablotron [5] open-source engine, written in C++.

schlenk I have made up a simple Tk GUI for using multiple processors. Not as polished and nice as tkxsltproc from the TclXSLT demo and missing some of its features, but maybe useful for someone. See A Tk GUI for multiple XSLT processors.

dkf: If XSLT's the answer, can I have a different question please?

gtdh Moved from XLST where I created this with a Typo (Doh!).

I started this page to capture an example of using XLST with Tcl from the Tcl News Group. Glenn Halstead

Posted by Miko le pepe <michel.salvagniac@free.fr> on 12/06/2004 20:50

To invoke an extension in an XSL stylesheet, first declare the extension in your Tcl script. For example:

::xslt::extension add http://www.zveno.com/Example ::example

Then use the normal XSLT extension mechanism. The XML Namespace matches the extension to the registered Tcl namespace (NB. the stylesheet author is free to choose any prefix for the extension namespace.) For example,
 <xsl:stylesheet version='1.0'

   <xsl:template match='/'>
     <xsl:text>Result of calling extension is "</xsl:text>
     <xsl:value-of select='eg:myfunc("foo")'/>


This stylesheet would result in the following Tcl script being evaluated:
 ::example::myfunc foo

Miko la honte

I must say that the above code is extract from the TclXSLT's docs of the ActiveState distribution...

See also: tkxsltproc

SRB: 2004-06-15: Added Tcl script requirement and modified stylesheet to include extension-element-prefixes attribute.

I (CJL) have been making my first forrays into XSLT, with mixed success. I wish to transform some XML which defines some registers in a piece of hardware into HTML for documentation purposes (done, no problem) and also into a .h header file for compiling into a library. That second transformation is proving troublesome when it comes to outputting spaces - I've started a thread on StackOverFlow [6], but it's not attracted the attentions of anyone from the tdom/Tcl world. I've yet to add it to the SO thread, but padding out the text via a template function to achieve aligned columns has had the side effect of making the first problem moot. I was under the impression (from reading the discussion section of the tdom page) that tdom was one of the more compliant engines, but the consensus on SO seems to be that it leaves something to be desired in that area.

DKF: It's compliant, but only if you get the document loaded correctly (where there's a bug). Be aware of the -keepSpaces option to tDOM's [dom parse] command.