[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] two at a time, using a sequence expression
Hi XSLers, I'm curious if there is a more elegant way to use a sequence expression to process two adjacent elements at a time. With XSLT 1.0 I would have used recursion, but with XSLT/XPath 2.0 I'm wondering if I can exploit sequences. Below is something I've come up with so far. An interesting side note, I thought the sequence expression would error because of divide by zero, but it appears to be side effect free, at least with Saxon. INPUT <?xml version="1.0" encoding="UTF-8"?> <pairs> <Abbott /> <Costello /> <Amos /> <Andy /> <George /> <Gracie /> <Einstein /> </pairs> XSLT <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output indent="yes" /> <xsl:template match="/pairs"> <xsl:copy> <xsl:for-each select="for $i in 1 to (count(*) idiv 2 + (count(*) mod 2)) return *[($i*2)-1]"> <pair> <xsl:copy-of select="." /> <xsl:copy-of select="./following-sibling::*[1]" /> </pair> </xsl:for-each> </xsl:copy> </xsl:template> </xsl:stylesheet> -- John Cavalieri john.cavalieri@xxxxxxxxx
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|