[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Excluding an element with specific content from an

Subject: Re: Excluding an element with specific content from an <xsl:sort> call
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Sun, 31 Jan 2010 03:07:59 +0100
Re:  Excluding an element with specific content from an
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@CraneSo                                             
             ftwrights.com>                                             To 
                                       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>   
             01/30/2010 10:23                                           cc 
             PM                                                            
                                                                   Subject 
                                       Re:  Excluding an element with 
             Please respond to         specific content from an            
             xsl-list@xxxxxxxx         <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@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.