June 2008
Intermediate to advanced
986 pages
27h 8m
English
[2.0] reverse()
Given a sequence of items, returns a sequence with the items in reverse order.
item()*reverse(item()*)
A sequence of items. If the sequence is the empty sequence, the empty sequence is returned.
A sequence with the input items in reverse order.
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.1, “General Functions and Operators on Sequences.”
Here is a short stylesheet that creates a sequence and
prints it, and then prints the sequence again after invoking the
reverse() function against
it:
<?xml version="1.0"?> <!-- reverse.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:datatest="http://www.oreilly.com"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="testSequence" as="item()*"> <xsl:sequence select="(3, 4, 5, current-date(), current-time(), 8, 'blue', 'red', xs:float(3.14), 42, xs:date('1995-04-21'))"/> </xsl:variable> <xsl:text>
Here is a test of the reverse() </xsl:text> <xsl:text>function:
</xsl:text> <xsl:text>
 Our original sequence is:

 </xsl:text> <xsl:value-of select="$testSequence" separator="
 "/> <xsl:text>

 Passing our sequence to reverse() </xsl:text> <xsl:text>gives us:

 </xsl:text> <xsl:value-of select="reverse($testSequence)" separator="
 "/> </xsl:template> </xsl:stylesheet>
Here are the results:
Here is a test of the reverse() function: Our ...
Read now
Unlock full access