Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Subject: How can I use XSLT / Xpath to sort elements for display and treat the last one displayed differently? Subject: How can I use XSLT / Xpath to sort elements for display and treat the last one displayed differently?To: NULL Date: 1/8/2008 2:49:00 AM Hello I am trying to use XSLT to display an XML document on a web-browser. The XML document has products that contain ingredients: <product> <ingredients> <ingredient mass-order="2">apple juice</ingredient> <ingredient mass-order=1"">orange juice</ingredient> <ingredient mass-order="3">banana</ingredient> </ingredients> </product> I want the ingredients of each product displayed in sequence with the lowest 'mass-order' ingredient first and the highest last etc. I also want commas between the ingredients and a full-stop after the last one like so: Orange juice, apple juice, banana. I used 'xsl:for-each' to loop through the ingredients and sorted the ingredients by mass-order before using 'xsl:value-of' to display the ingredient. I also added the following to the 'xsl:for-each' element: <xsl:choose> <xsl:when test=". != ../ingredient[last()]"> <span>, </span> </xsl:when> <xsl:otherwise> <span>.</span> </xsl:otherwise> </xsl:choose> However I expected this to put a '.' after the last displayed ingredient but it actually puts it after the last ingredient in the XML mark-up so that if it is not displayed last it still has a full- stop after it. Does anyone know how to achieve my goal? To reiterate I want the ingredients sorted and then displayed with commas after all but the last displayed ingredient which I want to have a '.' after it. Thanks AM | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
