From the course: XML Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Sorting data
- [Instructor] Let's wrap up this chapter by seeing how we can use xslt to apply sorting to the incoming XML data. I'm going to open up sorting.xml and sorting.xslt. The sorting.xml file is the same one we've been using in this chapter, and you can see here in the sorting xsl:stylesheet I've already got a for each tag inside my template, and I've left the xsl:choose construct from the previous exercise in place to apply some styling to the items in the XML. So all we need to do to sort the data in the collection we're interested in is to use the xsl:sort tag, so I'm going to add that right below the for each tag. So I'll add xsl:sort, and then xsl:sort takes two attributes. The first is the select, so I need to select the tag or attribute that I'm sorting on. In this case, I'm going to sort on the available attribute, and then I need to specify the order, and in this case I'll use descending order. All right, so that's pretty much all I need to do, so let's open this in the browser…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.