xsl-list
[Top] [All Lists]

RE: [xsl] How to cast current-group() ?

2009-04-27 16:31:23

the type of current-group() and current-grouping-key() is 
item()* and xs:anyAtomicType?. I wonder how to cast them to 
what really is in them.

   <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>

In my example, the function myfh:MakeTabelRow(.,.) takes the 
parameters as="element(*,my:matchType)*" and as="schema- 
element(my:team)" respectively both complexTypes. My 
workaround is to leave the function parameters untyped, not 
really ingenious...


current-grouping-key() is an atomic value, not an element. You could
construct an element and give it a type by validating it, but I suspect
that's not what you want to do. I would suggest:

<xsl:copy-of select="myfn:MakeTableRow(current-group()[1]/team,
current-group())"/>

though I can't see enough of your code to know whether that will fix the
problem.

Note that unless you're using an XSLT 2.0 processor that does strict static
typing, which is unlikely, as I don't think one exists and I don't think
anyone would be foolish enough to write one, it doesn't matter that the
static type of current-group() is item()* - it's the dynamic type that
matters, and so long as /results/match selects elements that have been
validated against the schema type my:matchType, the function call should
work. I think it's failing on the first argument, not the second, though you
don't show any error messages.

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--