Subject: Re: [xsl] Group by Element based on Attribute inside container using 1.0 From: Michael Ludwig <mlu@xxxxxxxxxxxxx> Date: Wed, 12 Nov 2008 16:53:14 +0100 |
Outstanding! I did a little research on the Sort. Your method did sort by year, but not exactly the way I wanted. Partly because I did not mention the most recent year first.
And partly, and probably more significantly, because one of my substring expressions was wrong. I wrote substring( $date, 6, 4) to select the year part of the string "DD/MM/YYYY", but that selects "/YYY" whereas it should be "YYYY", which requires substring( $date, 7, 4). As I wrote, substring() in XPath is 1-based, not 0-based.
So the last digit of the year wasn't taken into account, which provided a wrong result.
I altered your statement removing the concat and two substrings (also note the third argument for substring is dropped) and produced the following:
<xsl:sort select="substring( ObjectClassField[ @name = 'Date Inspected'], 6)" order="descending"/>
This sorts on "/YYYY", and it accidentally works here, as in your data sample there don't seem to be two inspections in one year. It would be more robust, however, to use either YYYYMMDD:
<xsl:sort select="concat( substring( ObjectClassField[ @name = $inspected], 7, 4), substring( ObjectClassField[ @name = $inspected], 1, 2), substring( ObjectClassField[ @name = $inspected], 4, 2))"/>
<xsl:sort select="substring(ObjectClassField[@name = $inspected], 7, 4)"/> <xsl:sort select="substring(ObjectClassField[@name = $inspected], 1, 2)"/> <xsl:sort select="substring(ObjectClassField[@name = $inspected], 4, 2)"/>
With a variable $inspected defined outside the xsl:apply-templates or xsl:for-each that is sorted:
And of course sorting years as strings only works when they all have the same number of digits, so in order to sort years like -44 (44 BC), 0, 800, or 10123, you want:
But then, you'd also need some more intelligent substring work to parse the dates.
Thank you for your help and patience. darris
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Group by Element based on, Friend, Darris E | Thread | [xsl] How can I know if a node has , Frédéric Choubelle |
RE: [xsl] Matching using variable o, Michael Kay | Date | RE: [xsl] Without parentnode, how t, V.Ramkumar |
Month |