/ Published in: XSLT
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!-- The stylesheet will transform this XML document: <doc> <SortPrefixAndTitle>3|Third Course</SortPrefixAndTitle> <SortPrefixAndTitle>1|First Course</SortPrefixAndTitle> <SortPrefixAndTitle>2|Second Course</SortPrefixAndTitle> </doc> into: <courseTitles> <courseTitle>First Course</courseTitle> <courseTitle>Second Course</courseTitle> <courseTitle>Third Course</courseTitle> </courseTitles> --> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <courseTitles> <xsl:apply-templates select="//SortPrefixAndTitle"> <xsl:sort select="substring-before(.,'|')"> </xsl:sort> </xsl:apply-templates> </courseTitles> </xsl:template> <xsl:template match="SortPrefixAndTitle"> <xsl:variable name="title" select="substring-after(.,'|')" /> <courseTitle> <xsl:value-of select="$title" /> </courseTitle> </xsl:template> </xsl:stylesheet>
URL: xsl-sort-substrings