Re: [xsl] position last and attributes

Subject: Re: [xsl] position last and attributes
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Sep 2012 15:23:24 -0400
At 2012-09-20 14:16 -0400, John P. McCaskey wrote:
On 9/20/2012 1:41 PM, G. Ken Holman wrote:
At 2012-09-20 13:08 -0400, John P. McCaskey wrote:
Though not required to by spec, in practice do the major XSL processors treat attributes in document order, alphabetical order, or any other repeated order?

When writing XSL, I sometimes need to jump through hoops that could be avoided if I knew the processor would treat the attributes in the same order every time. If I knew what that order is, all the better.

My code might not work on a different XSLT processor or be guaranteed to work with different revs, but often that's OK.

Could you characterize where in your algorithms you find the order of nodes along the attribute axis important or useful?
An example right now is a stylesheet that renders TEI documents in a browser. The attributes of an element are listed in two places, displayed differently. I'd prefer they get displayed in the same order in both places.

And since I know that encoders in this community, by habit and tool, enter attributes in a certain order, I'd like the displayed order to be document order.

I'm sure you mean to say "specified order" here, because I think we've established there is no document order for attributes.


Given that XSLT is not designed for markup preservation, there would be other aspects of the document expression lost in your display (e.g. entity references). That specified order happens to be used is a serendipitous coincidence for your application of XSLT.

Right now, I'm just guessing that the processor will use document order, and so far I've been right. Fortunately, if it doesn't, nothing catastrophic happens. So I'm not bothering with any hoop jumping on this one.

I agree. I see what you see in that a number of processors appear to put the attributes on the attribute axis in specified order, followed by the unspecified defaulted attributes in declaration order.


A test is below.

. . . . . . . . . Ken

t:\ftemp>type doc.xml
<!DOCTYPE doc [
<!ATTLIST doc two CDATA "TWO">
<!ATTLIST doc five CDATA "FIVE">
<!ATTLIST doc four CDATA "FOUR">
]>
<doc one="one" two="two" three="three"/>

t:\ftemp>type doc.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">
<xsl:template match="/*">
  <xsl:text>&#xa;</xsl:text><xsl:value-of select="@*[1]"/>
  <xsl:text>&#xa;</xsl:text><xsl:value-of select="@*[2]"/>
  <xsl:text>&#xa;</xsl:text><xsl:value-of select="@*[3]"/>
  <xsl:text>&#xa;</xsl:text><xsl:value-of select="@*[4]"/>
  <xsl:text>&#xa;</xsl:text><xsl:value-of select="@*[5]"/>
</xsl:template>
</xsl:stylesheet>

t:\ftemp>xslt-saxon doc.xml doc.xsl doc.out

t:\ftemp>type doc.out
<?xml version="1.0" encoding="utf-8"?>
one
two
three
FIVE
FOUR
t:\ftemp>xslt-xt doc.xml doc.xsl doc.out

t:\ftemp>type doc.out
<?xml version="1.0" encoding="utf-8"?>

one
two
three
FIVE
FOUR
t:\ftemp>xslt-xalan doc.xml doc.xsl doc.out

t:\ftemp>type doc.out
<?xml version="1.0" encoding="UTF-8"?>
one
two
three
FIVE
FOUR
t:\ftemp>

t:\ftemp>xslt-msxsl doc.xml doc.xsl doc.out

t:\ftemp>type doc.out
<?xml version="1.0" encoding="UTF-16"?>
one
two
three
FIVE
FOUR
t:\ftemp>



--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Current Thread