Author: Steven Neiland

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

XSL Breakdown - Continued

Continuing our code breakdown of our xsl sheet, we come to the body of the for-each loop. Again you will note html mixed in with xsl. I am skipping the html component of the code here.

Position Test

This little snippet of code determines if we are on an even or odd number row of our loop. If it even we give the attribute "class" a value of 'even'. This is class attribute applied to the <tr> html tag.

<xsl:if test="position() mod 2 != 1">
<xsl:attribute name="class">even</xsl:attribute>


The code group in the loop converts the url->loc node into a functional hyperlink.

<xsl:variable name="itemURL">
<xsl:value-of select="sitemap:loc"/>
<a href="{$itemURL}"><xsl:value-of select="sitemap:loc"/></a>

Priority As A Percentage

This line takes the priority value converts it into a percentage by multiplying by 100 and then string concatenates it with the % symbol before outputing to the screen.

<xsl:value-of select="concat(sitemap:priority*100,'%')"/>

Capitalize Change Frequency

Of all the code this is the most complex, and probably the least useful. All it really does is take the change frequency value, gets the uppercase of the first letter and lowercase of the rest and concatenates it back into one string. This is where the upper and lower variables are used.

According to the xsl documentation it should be possible to use an upper-case function, however I have not been able to get it to work. I found this code on the net, and while its ugly it works.

<xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),
concat($lower, $upper),concat($upper, $lower)),
substring(sitemap:changefreq, 2))"

Last Change

Finally we split the last modified value seperating the two components "date" and "time" with a space.

<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),
concat(' ',substring(sitemap:lastmod,12,5)))"

1 2 3 4 5 6 7

What Do You Think?

Reader Comments

Post a Comment

Comment Etiquette:

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain or appear to be advertisments, will not be published.
  • Comments that appear to be created for the purpose of linkbuilding to commercial sites will be removed.

We are all adults here so play nice.


Archives Blog Listing

Tag Listing

Learn CF In A Week


Fork me on GitHub