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

Muenchian Sorting with Substrings and Translated Strin

Subject: Muenchian Sorting with Substrings and Translated Strings...
From: Brook Ellingwood <brook@xxxxxxxxxxx>
Date: Sat, 21 Feb 2004 22:05:59 -0800
dsla 1 100
Hi,

I've got two issues I need to deal with in sorting a product list. Here's
some sample XML:
<List>
<Product>
   <ProductName>CFD 1-100</ProductName>
   <ProductFamily>1&quot; CFD</ProductFamily>
</Product>
<Product>
   <ProductName>CFD 1-100 Pro</ProductName>
   <ProductFamily>1&quot; CFD</ProductFamily>
</Product>
<Product>
   <ProductName>CFD 1.5-100</ProductName>
   <ProductFamily>1.5&quot; CFD</ProductFamily>
</Product>
<Product>
   <ProductName>CFD 2-100</ProductName>
   <ProductFamily>2&quot; CFD</ProductFamily>
</Product>
<Product>
   <ProductName>DSLA 1.5-100</ProductName>
   <ProductFamily>1.5&quot; DSLA</ProductFamily>
</Product>
<Product>
   <ProductName>DSLA 1-100</ProductName>
   <ProductFamily>1&quot; DSLA</ProductFamily>
</Product>
</List>

I'm sorting first by ProductFamily, and then by ProductName. I was doing
this first on MSXML and getting the result:

Family: 1&quot; CFD
   CFD 1-100
   CFD 1-100 Pro

Family: 1&quot; DSLA
   DSLA 1-100

Family: 1.5&quot; CFD
   CFD 1.5-100

Family: 1.5&quot; DSLA
   DSLA 1.5-100

Family: 2&quot; CFD
   CFD 2-100

My first challenge is that I want to change the ProductFamily sort so that
it groups first by the alpha characters, and then by the numerical ones. I
seems that I need to turn the value of ProductFamily into a string so I can
sort on substrings but that can't work.

My second challenge is similar -- this is migrating from ASP with MSXML to
PHP with Sablotron, and when I test it on Sablotron, the initial sort is
getting messed up by what appears to be a bug -- it doesn't seem to be
sorting the decimals, and instead gives me this:

Family: 1.5&quot; CFD
   CFD 1.5-100

Family: 1.5&quot; DSLA
   DSLA 1.5-100

Family: 1&quot; CFD
   CFD 1-100
   CFD 1-100 Pro

Family: 1&quot; DSLA
   DSLA 1-100

Family: 2&quot; CFD
   CFD 2-100

Again, it seems like the workaround is sorting on the value of a string,
this time with the translate() function applied to strip out the decimal
points. But again, that can't be done. Or can it? Does anyone have a good
idea for this one?

Here's the relevant parts of the XSL as they stand now:

<xsl:key name="FamilySort" match="Product" use="ProductFamily" />

<xsl:for-each 
select="document('../data/products.xml')/dataroot/Product[generate-id(.) =
generate-id(key('FamilySort', ProductFamily)[1])]">
        <xsl:sort select="./ProductFamily"/>
        <xsl:if test="not(. = preceding::ProductFamily)">
               <xsl:text>Family: </xsl:text>
               <xsl:value-of select="./ProductFamily"/>
        </xsl:if>
       <xsl:for-each select="key('FamilySort', ProductFamily)">
           <xsl:sort select="./ProductName"/>
           <xsl:variable name="ProductName" select="./ProductName"/>
       </xsl:for-each>
</xsl:for-each>    


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.