Multi-stage XSLT in Ant

Inasmuch as Ant is good at re-running an XSLT transformation or a series of transformations when the XML source changes but not so good at re-running when one of the transformations’ stylesheets’ sub-modules changes, it’s a simple thing to generate on-the-fly a temporary build file containing paths listing the dependencies of each stylesheet so Ant can do the right thing. Continue reading “Multi-stage XSLT in Ant”

XSLT 3.0 testbed

Inasmuch as few people yet have much (or any) experience using XSLT 3.0 on more than toy examples, https://github.com/MenteaXML/xslt3testbed is a public, medium-sized XSLT 3.0 project where people could try out new XSLT 3.0 features on the transformations to (X)HTML(5) and XSL-FO that are what we do most often and, along the way, maybe come up with new design patterns for doing transformations using the higher-order functions, partial function application, and other goodies that XSLT 3.0 gives us. Continue reading “XSLT 3.0 testbed”

Is there life after libXSLT 1?

Inasmuch as I was talking at Balisage about adapting the Saxon-CE event model to XSL-FO, I ended up talking with Lauren Wood and Matt Patterson about the general case for a XSLT 2.0 processor, or a processor for a subset of XSLT 2.0, that could be used in language bindings and web browsers as a replacement for the stuck-at-XSLT-1.0 libXSLT processor.

Since we were going to talk about it more at the XML Summer School anyway, I did a five-minute lightning talk (slides) at the “unconference sessions”. Happily, it got more people at the Summer School trying things. Michael Kay of Saxonica was at the presentation, and not only did he welcome the idea of compiling Saxon to C, Saxonica now state that they’re looking at the possibility.

XML Summer School 2013

Inasmuch as the offer’s open a bit longer, you can still use the XML13 discount code for a 10% discount on your fees for this year’s XML Summer School.

This year, with Patricia Walmsley, I’m teaching Improv­ing stylesheets through the use of advanced features in the XSLT and XQuery track:

Most XSLT developers stick to a famil­iar core set of XPath and XSLT instruc­tions and func­tions. There are a num­ber of advanced fea­tures, many of them intro­duced in ver­sion 2.0, that appear only rarely in stylesheets even though they can be very use­ful in cer­tain situ­ations. In this course, we will explore some of these less-used fea­tures, show­ing inter­act­ively how they can be applied to improve exist­ing XSLT stylesheets. XPath fea­tures covered will include oper­at­ors like inter­sect and except, << and >>, quan­ti­fied expres­sions, and 2.0 func­tions that can sig­ni­fic­antly sim­plify your stylesheets. XSLT fea­tures covered will include group­ing, reg­u­lar expres­sion match­ing and advanced mod­u­lar­iz­a­tion using modes and instruc­tions like xsl:apply-imports and xsl:next-match.

Other sessions in the track are XSLT Effi­ciency and Effectiveness taught by Michael Kay, Query­ing XML Data­bases with XQuery taught by Adam Ret­ter, and Trends in XSLT/XQuery taught by Florent Georges, while the other tracks during the week are XML Primer, Hands-on Introduction to XML, Publishing With XML, Semantic Technologies, Trends and Transients, and Hands-on Web Publishing. There's also the evening events, such as punting, the formal dinner, and the unconference session, where I'm lined up to present a lightning talk.

use-when

Inasmuch as use-when is one of the standard attributes in XSLT 2.0 (and later) rather than being on a particular XSLT element, it seldom gets much of a mention; e.g., currently only 568 mentions on the XSL-List according to MarkMail (and some of those are false positives).

use-when (and xsl:use-when on non-XSLT elements) is for “conditional element inclusion” and is very useful for excluding elements that either aren’t currently useful or that will cause errors if acted upon. The use-when in the example below causes the xsl:value-of to be used only when saxon:line-number() is available, thereby avoiding the Saxon extension functions are not available under Saxon-HE message from more recent versions of Saxon HE where saxon:line-number() is no longer available but producing a useful result on older Saxon HE versions where the function is available.

<!-- Leftover intermediate elements. -->
<xsl:template match="t:*">
  <xsl:if test="$debug">
    <xsl:message>
      <xsl:value-of select="t:node-basename(.)" />
      <xsl:value-of
        use-when="function-available('saxon:line-number')"
        select="concat(':', saxon:line-number())"
        xmlns:saxon="http://saxon.sf.net/" />
      <xsl:text> :: </xsl:text>
      <xsl:copy-of select="." />
    </xsl:message>
  </xsl:if>
  <xsl:apply-templates />
</xsl:template>

The use-when expression is evaluated very early in the processing of the stylesheet, and you can’t use variable references in the expression. So don’t be tempted to try:

<xsl:message use-when="$debug">
...
</xsl:message>

xslide alive!

Inasmuch as you, like me, may have missed xslide’s “Template” menu when editing XSLT using Emacs’ nXML-mode, I’ve made available my “xslide2” XSLT mode for Emacs that I’ve been using for a while. This new xslide is a derived mode that uses nXML-mode for nearly everything and adds back some of the XSLT-specific parts of xslide.

Future development is happening on the Trac and Subversion for the xslide SourceForge project. See https://sourceforge.net/apps/trac/xslide/wiki/WikiStart.

Saxon feature keys for initial template and mode

Inasmuch as a “feature key” is how you configure a Java JAXP XSLT processor, it’s good to see that Saxon 9.3 has added feature keys for setting the initial template and initial mode. In fact, Saxon has gone from 30 feature keys in Saxon 9.0 to 70 in 9.2 and now 79 in 9.3.

Where this becomes useful (outside of your own Java programs) is being able to specify the initial template and/or mode in the <xslt> task in Ant build files. Continue reading “Saxon feature keys for initial template and mode”