June 2008
Intermediate to advanced
986 pages
27h 8m
English
Given XSLT 2.0’s emphasis on sequences, it makes sense that we would
have an operator to iterate through all the values of a sequence. Just
as the if operator lets you put the
logic of <xsl:choose> into an
XPath expression, the for
operator gives XPath expressions the power of <xsl:for-each>. Here is a stylesheet
with an example:
<?xml version="1.0"?> <!-- for.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:variable name="English-months" as="xs:string*" select="('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')"/> <xsl:variable name="German-months" as="xs:string*" select="('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember')"/> <xsl:template match="/"> <xsl:value-of select="for $m in ($English-months, $German-months) return if (starts-with($m, 'J')) then concat ($m, ' starts with J!
') else ''" separator=""/> </xsl:template> </xsl:stylesheet>
Read now
Unlock full access