[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to cast current-group() ?
Dear Michael
thank you for your input. I work with Saxon SA-9.1.0.6 which is not to bad with typing and not foolish strict neither... The problem is the XSLT processor allows me to use this code snippet <xsl:for-each-group select="/results/match" group-by="team"> <xsl:copy-of select="myfn:MakeTableRow(current-grouping- key(),current-group())"/> </xsl:for-each-group> with the function only without the type control... <xsl:function name="myf:MakeTableRow" as="schema- element(xhtml:tr)"> <xsl:param name="team"/> <!-- as="schema-element(res:team)" --> <xsl:param name="matches"/> <!-- as="schema- element(res:match)*" --> <tr xsl:validation="strict"> ... </tr> </xsl:function> your comment current-grouping-key() is an atomic value, not an element. You could is a solution to the problem, however not the most elegant one. Type casting would be nicer... I put the whole file in the end. Thanks again Leo <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform " xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:res="http://results.bla" xmlns:myf="http://leostuder.ch/funtions" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result- prefixes="xs res myf xhtml"> <xsl:output method="xhtml" encoding="ISO-8859-1" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd "/> <xsl:import-schema namespace="http://results.bla" schema- location="results.xsd"/> <xsl:import-schema namespace="http://www.w3.org/1999/xhtml" schema-location="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd "/> <xsl:function name="myf:MakeTableRow" as="schema- element(xhtml:tr)"> <xsl:param name="team"/> <!-- as="schema-element(res:team)" --> <xsl:param name="matches"/> <!-- as="schema- element(res:match)*" --> <tr xsl:validation="strict"> <td> <xsl:value-of select="$team"/> </td> <td> <xsl:value-of select="count($matches)"/> </td> <xsl:variable name="won" select="count($matches[res:team[.=$team]/@score gt res:team[.!=$team]/@score])" as="xs:integer"/> <td> <xsl:value-of select="$won"/> </td> <td> <xsl:value-of select="count($matches[res:team[.=$team]/@score lt res:team[.!=$team]/@score])"/> </td> <xsl:variable name="drawn" select="count($matches[res:team[.=$team]/@score eq res:team[.!=$team]/@score])" as="xs:integer"/> <td> <xsl:value-of select="$drawn"/> </td> <td> <xsl:value-of select="sum($matches/res:team[.=$team]/ @score)"/> </td> <td> <xsl:value-of select="sum($matches/res:team[.!=$team]/ @score)"/> </td> <td> <xsl:number value="3*$won+$drawn"/> </td> </tr> </xsl:function> <xsl:template match="/"> <html xsl:validation="strict"> <!-- xsl:validation="strict" possible in html tag --> <head> <title>Spielresultate</title> </head> <body> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="res:results"> <h2>Results</h2> <table cellpadding="10"> <thead> <tr> <td>Team</td> <td>Played</td> <td>Won</td> <td>Lost</td> <td>Drawn</td> <td>For</td> <td>Against</td> <td>Points</td> </tr> </thead> <xsl:variable name="teamResults" as="schema- element(xhtml:tr)*"> <xsl:for-each-group select="/res:results/res:match" group-by="res:team"> <xsl:sequence select="myf:MakeTableRow(current- grouping-key(),current-group())"/> </xsl:for-each-group> </xsl:variable> <xsl:for-each select="$teamResults"> <xsl:sort select="./xhtml:td[8]" order="descending" data-type="number"/> <xsl:sort select="./xhtml:td[6]" order="descending"/> <xsl:sort select="./xhtml:td[7]" order="ascending"/> <xsl:copy-of select="."/> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
|
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
|