This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
This can't be right, XML with no root element: Saxon & XT vs. Xalan
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] This can't be right, XML with no root element: Saxon & XT vs. Xalan
- From: "Dylan Walsh" <Dylan dot Walsh at Kadius dot com>
- Date: Thu, 26 Jul 2001 16:29:11 +0100
- Reply-To: xsl-list at lists dot mulberrytech dot com
I've been evaluating Schematron. There is an example that tests for WAI
conformance. I've noticed that the validation transformation that it
generates, does not use the text output mode, and yet it does not
produce a root element, just text. So you get output like:
<?xml version="1.0" encoding="utf-8"?>(1.1) An image element should have
some descriptive text: an alt or longdesc attribute.(1.1) An input
element should have some descriptive text: an alt or longdesc attribute.
{ ...and so on...}
The XSLT code is at the bottom of this document.
XT and InstantSaxon 6.2.2 apply the transformation without error. Xalan
1.2 (via Cocoon 1.8.2) reacts thusly:
"org.apache.xalan.xslt.XSLProcessorException: Warning: can't output text
before document element! Ignoring... "
Personally I'm with the Apache people on this one.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sch="http://www.ascc.net/xml/schematron" version="1.0">
<axsl:template match="*|@*" mode="schematron-get-full-path">
<axsl:apply-templates select="parent::*"
mode="schematron-get-full-path"/>
<axsl:text>/</axsl:text>
<axsl:if test="count(. | ../@*) = count(../@*)">@</axsl:if>
<axsl:value-of select="name()"/>
<axsl:text>[</axsl:text>
<axsl:value-of
select="1+count(preceding-sibling::*[name()=name(current())])"/>
<axsl:text>]</axsl:text>
</axsl:template>
<axsl:key name="imgkey" match="img | IMG" use="@alt"/>
<axsl:template match="/">
<axsl:apply-templates select="/" mode="M1"/>
<axsl:apply-templates select="/" mode="M2"/>
<axsl:apply-templates select="/" mode="M3"/>
<axsl:apply-templates select="/" mode="M4"/>
<axsl:apply-templates select="/" mode="M5"/>
<axsl:apply-templates select="/" mode="M6"/>
<axsl:apply-templates select="/" mode="M7"/>
<axsl:apply-templates select="/" mode="M8"/>
<axsl:apply-templates select="/" mode="M9"/>
</axsl:template>
<axsl:template match="img | IMG" priority="4000" mode="M1">
<axsl:choose>
<axsl:when test="@alt or @ALT or @longdesc or
@LONGDESC"/>
<axsl:otherwise>(1.1) An image element should have some
descriptive text: an alt or longdesc attribute.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M1"/>
</axsl:template>
<axsl:template match="input | INPUT" priority="3999" mode="M1">
<axsl:choose>
<axsl:when test="@alt or @ALT"/>
<axsl:otherwise>(1.1) An input element should have some
descriptive text: an alt or longdesc attribute.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M1"/>
</axsl:template>
<axsl:template match="applet | APPLET " priority="3998" mode="M1">
<axsl:choose>
<axsl:when test="@alt or @ALT"/>
<axsl:otherwise>(1.1) An applet element should have some
descriptive text: an alt or longdesc attribute.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M1"/>
</axsl:template>
<axsl:template match="map | MAP" priority="3997" mode="M1">
<axsl:choose>
<axsl:when test="area/@alt or a or A or AREA/@ALT"/>
<axsl:otherwise>(1.1) A map element should have some
descriptive text: an alt attribute or a link.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M1"/>
</axsl:template>
<axsl:template match="object | OBJECT" priority="3996" mode="M1">
<axsl:choose>
<axsl:when test="string-length(text()) > 0"/>
<axsl:otherwise>(1.1) An object element should contain some
descriptive text.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M1"/>
</axsl:template>
<axsl:template match="frame | FRAME " priority="3995" mode="M1">
<axsl:choose>
<axsl:when test="@longdesc or @LONGDESC"/>
<axsl:otherwise>(1.1) A frame element should have some
descriptive text: a longdesc attribute.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M1"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M1"/>
<axsl:template match="body | BODY" priority="4000" mode="M2">
<axsl:if test="string(@bgcolor) = string(@color)">(2.2) The
background color and the foreground color are the same</axsl:if>
<axsl:apply-templates mode="M2"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M2"/>
<axsl:template match="b | I | i | B" priority="4000" mode="M3">
<axsl:if test="self::*">(3.3) Concerning element<axsl:text
xml:space="preserve"> </axsl:text>
<axsl:value-of select="name(.)"/>
<axsl:text xml:space="preserve"> </axsl:text>: B and I are not
recommended. Use strong and em, or stylesheets.</axsl:if>
<axsl:apply-templates mode="M3"/>
</axsl:template>
<axsl:template match="ul | ol | UL | OL " priority="3999"
mode="M3">
<axsl:choose>
<axsl:when test="li or LI"/>
<axsl:otherwise>(3.3) A list should not be used for formatting
effects</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M3"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M3"/>
<axsl:template match="html | HTML | body | BODY" priority="4000"
mode="M4">
<axsl:choose>
<axsl:when test="@lang or @xml:lang or @LANG "/>
<axsl:otherwise>(4.3) The primary language of a document should
be identified.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M4"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M4"/>
<axsl:template match="table | TABLE" priority="4000" mode="M5">
<axsl:choose>
<axsl:when test="caption or CAPTION"/>
<axsl:otherwise>(5.1) A table should have a
caption</axsl:otherwise>
</axsl:choose>
<axsl:choose>
<axsl:when test="@summary or @SUMMARY"/>
<axsl:otherwise>(5.5) A table should have a summary
attribute</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M5"/>
</axsl:template>
<axsl:template match="td | TD" priority="3999" mode="M5">
<axsl:choose>
<axsl:when test="@scope or @headers or @axis or @SCOPE
or @HEADERS or @AXIS "/>
<axsl:otherwise>(5.2) Table data should identify its scope,
headers, axis in attributes.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M5"/>
</axsl:template>
<axsl:template match="th | TH" priority="3998" mode="M5">
<axsl:choose>
<axsl:when test="@abbr or @ABBR"/>
<axsl:otherwise>(5.6) A table header should have an abbr
attribute to give abbreviation</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M5"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M5"/>
<axsl:template match="*[@onmouseup]" priority="4000" mode="M6">
<axsl:choose>
<axsl:when test="@onkeyup or @ONKEYUP"/>
<axsl:otherwise>(6.4) If you specify an "onmouseup" attribute
on a<axsl:text xml:space="preserve"> </axsl:text>
<axsl:value-of select="name(.)"/>
<axsl:text xml:space="preserve"> </axsl:text>element, you
should also specify an "onkeyup" attribute</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M6"/>
</axsl:template>
<axsl:template match="*[@onmousedown] | *[@ONMOUSEDOWN]"
priority="3999" mode="M6">
<axsl:choose>
<axsl:when test="@onkeydown or @ONKEYDOWN"/>
<axsl:otherwise>(6.4) If you specify an "onmousedown" attribute
on a<axsl:text xml:space="preserve"> </axsl:text>
<axsl:value-of select="name(.)"/>
<axsl:text xml:space="preserve"> </axsl:text>element, you
should also specify an "onkeydown" attribute</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M6"/>
</axsl:template>
<axsl:template match="*[@onclick] | *[@ONCLICK]" priority="3998"
mode="M6">
<axsl:choose>
<axsl:when test="@onkeypress or @ONKEYPRESS"/>
<axsl:otherwise>(6.4) If you specify an "onclick" event on
a<axsl:text xml:space="preserve"> </axsl:text>
<axsl:value-of select="name(.)"/>
<axsl:text xml:space="preserve"> </axsl:text>element, you
should also specify an "onkeypress"</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M6"/>
</axsl:template>
<axsl:template match="marquee | MARQUEE" priority="3997" mode="M6">
<axsl:choose>
<axsl:when test="*"/>
<axsl:otherwise>(6.5) The marquee element is not good
HTML</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M6"/>
</axsl:template>
<axsl:template match="blink | BLINK" priority="3996" mode="M6">
<axsl:choose>
<axsl:when test="*"/>
<axsl:otherwise>(6.5) The blink element is not good
HTML</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M6"/>
</axsl:template>
<axsl:template match="frame | FRAME" priority="3995" mode="M6">
<axsl:if test="contains(@src, '.gif') or
contains(string(@src), '.GIF') or contains(string(@src), '.jpg')
or contains(string(@src), '.JPG') or contains(string(@src),
'.jpeg') or contains(string(@src), '.JPEG') or
contains(string(@src), '.png') or contains(string(@src), '.PNG')
">(6.2) A frame should not be a direct image</axsl:if>
<axsl:choose>
<axsl:when test="../noframes or ../NOFRAMES"/>
<axsl:otherwise>(6.5) If you specify a frame, also specify a
noframes element.</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M6"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M6"/>
<axsl:template match="meta | META " priority="4000" mode="M7">
<axsl:if test="@http-equiv = 'refresh'">(7.1) The user should
control the refreshing of the page</axsl:if>
<axsl:apply-templates mode="M7"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M7"/>
<axsl:template match="fieldset | FIELDSET" priority="4000"
mode="M8">
<axsl:choose>
<axsl:when test="legend or LEGEND"/>
<axsl:otherwise>(?) A fieldset should have a
legend</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M8"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M8"/>
<axsl:template match="frameset | FRAMESET" priority="4000"
mode="M9">
<axsl:choose>
<axsl:when test="@title or @TITLE"/>
<axsl:otherwise>(12.1) A frameset should have a
title</axsl:otherwise>
</axsl:choose>
<axsl:apply-templates mode="M9"/>
</axsl:template>
<axsl:template match="text()" priority="-1" mode="M9"/>
<axsl:template match="text()" priority="-1"/>
</axsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list