Published:
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>
</xsl:if>
Hyperlink
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"/>
</xsl:variable>
<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)))"/>
Reader Comments