3.5 Using a QName Output Method

I have explained the xml, html, and text output methods. You can also use a QName for a value of the method attribute. But there's a catch: if you use a QName, it must be supported as an extension by the XSLT processor that you use with it. (This mechanism allows you to invoke a user-written serializer, such as with a SAX ContentHandler.) This can be useful if you want to produce non-XML formats as your output.

Johannes Döbler's XSLT processor jd.xslt offers several QName values for the method attribute by way of extension. One of them is jd:empty.

The value of method must be a QName, not an NCName. Any value other than xml, html, or text is considered an extension and must be qualified with a namespace.


The jd:empty output method, when used together with the jd.xslt processor, produces a result tree but doesn't serialize it. This is useful when you are interested only in measuring the performance of the processor with a given stylesheet. The stylesheet empty.xsl uses output with a method of jd:empty:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="jd:empty" xmlns:jd="http://www.aztecrider.com/xslt"/>     <xsl:template match="name">  <name>   <family><xsl:apply-templates select="last"/></family>   <given><xsl:apply-templates select="first"/></given>  </name> </xsl:template>     </xsl:stylesheet>

The QName jd:empty is associated with the namespace name http://www.aztecrider.com/xslt. You can process empty.xsl against the document name.xml with jd.xslt to see what happens. (For details of how to download, install, and run jd.xslt, see the appendix.) To run it, enter the following at a command or shell prompt using the -verbose switch:

java -jar jdxslt.jar -verbose name.xml empty.xsl

You won't see a result, but the processor will deliver the following information:

jd.xslt processor version 1.4.0     java vm              = Sun Microsystems Inc., 1.4.1_01 parser               = org.apache.crimson.parser.XMLReaderImpl modelbuilder factory = jd.xml.xpath.model.build.ModelBuilderFactory read stylesheet      = file:C:/LearningXSLT/examples/ch03/empty.xsl prepare stylesheet   = 180 ms read xml input       = 10 ms (using normal tree model) transform input      = 10 ms max memory usage     = 1.937 MB

With -verbose, the processor reports the transformation performance results.



Learning XSLT
Learning XSLT
ISBN: 0596003277
EAN: 2147483647
Year: 2003
Pages: 164

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net