|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XSL selective alphabetical sort
Hi,
I am currently trying to alphabetically sort an xml file containing a list of movies. This proved pretty simple using the following: <xsl:for-each select="collection/movie"> <xsl:sort select="title" /> ....... </xsl:for-each> However, all the movies beginning with the word "The" are obviously listed together in the "T" section. I would like the sort to ignore articles at the start of the title. Does anyone know how to do this? Thanks |
|
#2
|
||||
|
||||
|
There is no immediate solution within the current XSL transformation because we are using an xsl:sort.
This is what you have now: XML_1 -> XSL_Transformation_1 -> output This is what you should do: XML_1 -> XSL_Transformation_2 -> XML_2 - > XSL_Transformation_1 -> output XSL_Transformation_2 takes all of the titles in XML_1 that begin with "The", remove the "The", and add ", The" to the end of the current title. This would then be added to the parent element with an element called sortTitle. titles that don't start with the would just be copied to the sortTitle element. This way you would keep the original title element for display purposes. Then just do the xsl:sort on sortTitle. If you need help writing the template for XSL_Transformation_2 let me know and I can help. |
|
#3
|
|||
|
|||
|
That sounds like it does something like what I want; however, I confess to being fairly new to xsl! Could you give me something of an example?
Thanks again |
|
#4
|
|||
|
|||
|
This is not a perfect solution as it ignores any occurence of "The " in the XML - you could possibly improve it using substring() somewhere in the xsl:sort ...
Code:
<xsl:for-each select="/collection/movie"> <xsl:sort select="translate(title, 'The ', '')"/> <xsl:value-of select="title"/> <br/> </xsl:for-each> |
|
#5
|
||||
|
||||
|
Teedee-
Your solution is no good. You don't have a good understanding of the translate function. I believe that you are under the impression that translate will replace all occurences of the word "The " with "", but it does not. What happens instead is that all 'T', 'h', 'e', and ' ' characters are replaces with ''. I am sticking to my original answer. Last edited by MattSidesinger : March 24th, 2004 at 04:49 PM. Reason: Change in answer - see bold text. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL selective alphabetical sort |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|