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

strip leading whitespace for sorting

Subject: strip leading whitespace for sorting
From: Joe Barwell <jbar@xxxxxxxx>
Date: Mon, 27 Oct 2008 21:13:56 +1300
 strip leading whitespace for sorting
Hello people,

XSLT 1.0, Firefox 3.0 & other recent browsers.

I've got a problem with nodes that contain leading whitespace that I want to strip, because it's affecting my sorts.

I've had a look at the list archives & dpawson's faq. Is it true that the only way to strip leading whitespace is as shown here: < http://www.dpawson.co.uk/xsl/sect2/N8321.html#d12429e833 >? It looks like a lot of hard work.

FWIW, below is my current xsl stylesheet, which gets called from within php... which is processing some pretty basic xml sent from a wsdl/soap thing-a-mejig (a list of countries & currencies).

As you can see, I've tried to use <xsl:strip-space elements="*" /> & <xsl:copy>, but may, in my ignorance, simply be misusing those tools.

TIA for any pointers. Cheers!

Joe


<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<!-- This is required so that &#160; is correctly rendered -->
<xsl:output encoding="iso-8859-1" />
<!-- Doesn't fix the problem with spaces affecting sort order -->
<xsl:strip-space elements="*" />

<xsl:template match="/">
<table border='2'><tr><th>Currency Name</th><th>Currency Code</th><th>Country Name</th><th>Country Code</th></tr>
<!-- Is this achieving anything? -->
<xsl:copy>
<xsl:for-each select="NewDataSet/Table">
<xsl:sort select="Currency" order="ascending" />
<xsl:sort select="Name" order="ascending" />
<xsl:call-template name="displayCurrency" />
</xsl:for-each>
</xsl:copy>
</table>
</xsl:template>



<xsl:template name="displayCurrency">
<xsl:variable name="theCurrencyName" select="Currency" />
<xsl:variable name="theCurrencyCode" select="CurrencyCode" />
<tr><td><xsl:value-of select="$theCurrencyName" />&#160;</td><td><xsl:value-of select="$theCurrencyCode" />&#160;</td><td><xsl:value-of select="Name" /></td><td><xsl:value-of select="CountryCode" /></td></tr>\n
</xsl:template>



</xsl:stylesheet>


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.