Under the assumption that 'A' only appears as length-1 string in Prefix
the following diff makes that stylesheet work on XSLT 1.0 processors:
$ diff mark.xsl mark1.xsl
10c10
< <xsl:sort select="if( Prefix!='A' ) then Prefix else ''"/>
---
<xsl:sort select="translate(Prefix,'A','')"/>
$
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
"G. Ken Holman"
<gkholman(_at_)CraneSo
ftwrights.com> To
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
01/30/2010 10:23 cc
PM
Subject
Re: [xsl] Excluding an element with
Please respond to specific content from an
xsl-list(_at_)lists(_dot_)mu <xsl:sort> call
lberrytech.com
At 2010-01-30 13:05 -0800, Mark Wilson wrote:
Thanks Ken,
But it did not work.
My bad ... in my haste I neglected to think of the behaviour
triggered in the "if" statement when the Prefix element is
absent. When an operand of the comparison operator is the empty set,
the comparison returns false.
It worked for me when I turned the expression inside out:
<xsl:sort select="if( Prefix!='A' ) then Prefix else ''"/>
Now the same '' value is used for sorting if the prefix is 'A' (the
test calculates as false) or the prefix is absent (the test defaults as
false).
I hope the illustration below helps. Note how document order is
maintained for all records that have no prefix or the prefix is 'A',
thus proving they are being sorted with the same value.
. . . . . . . . . . . Ken
T:\ftemp>type mark.xml
<tests>
<record>
<order>1</order>
<Prefix>D</Prefix>
</record>
<record>
<order>2</order>
<Prefix>A</Prefix>
</record>
<record>
<order>3</order>
<Prefix>L</Prefix>
</record>
<record>
<order>4</order>
<Prefix>A</Prefix>
</record>
<record>
<order>5</order>
</record>
<record>
<order>6</order>
<Prefix>A</Prefix>
</record>
<record>
<order>7</order>
</record>
<record>
<order>8</order>
<Prefix>L</Prefix>
</record>
<record>
<order>9</order>
<Prefix>D</Prefix>
</record>
</tests>
T:\ftemp>call xslt2 mark.xml mark.xsl
<?xml version="1.0" encoding="UTF-8"?>
<tests>
<record>
<order>2</order>
<Prefix>A</Prefix>
</record>
<record>
<order>4</order>
<Prefix>A</Prefix>
</record>
<record>
<order>5</order>
</record>
<record>
<order>6</order>
<Prefix>A</Prefix>
</record>
<record>
<order>7</order>
</record>
<record>
<order>1</order>
<Prefix>D</Prefix>
</record>
<record>
<order>9</order>
<Prefix>D</Prefix>
</record>
<record>
<order>3</order>
<Prefix>L</Prefix>
</record>
<record>
<order>8</order>
<Prefix>L</Prefix>
</record>
</tests>
T:\ftemp>type mark.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="tests">
<xsl:copy>
<xsl:for-each select="record">
<xsl:sort select="if( Prefix!='A' ) then Prefix else ''"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
T:\ftemp>rem Done!
--
UBL and Code List training: Copenhagen, Denmark 2010-02-08/10
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training: San Carlos, California 2010-04-26/30
Vote for your XML training: http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--