Error using nested for-each-group in Oracle XSLT
Hello everyone. Thank you for taking the time to view this thread.
I created an XSLT which works in Oxygen but is not working in Oracle.
Given this xml -
<Country>
<info enum="CTRY" name="United Sates of America" total-states="50" />
<info enum="ST" index='0' sname="New York" population="8,244,910"/>
<info enum="ST" index='0' sname="Chicago" population="2,707,120"/>
<info enum="CTRY" name="Germany" total-states="16"/>
<info enum="ST" index='1' sname="Berlin" population="3,469,910"/>
<info enum="ST" index='1' sname="Brandenburg" population="2,500,000"/>
</Country>
Working XSLT in Oxygen -
<xsl:template match="/">
<Country>
<xsl:for-each-group select="Country/*" group-starting-with="info[@enum='CTRY']">
<CountryInfo>
<xsl:call-template name="ctry"/>
</CountryInfo>
</xsl:for-each-group>
</Country>
</xsl:template>
<xsl:template name="ctry">
<name>Country Name: <xsl:value-of select="@name"/></name>
<districts><xsl:value-of select="@total-states"/></districts>
<xsl:for-each-group select="current-group()" group-by="@index">
<xsl:call-template name="states"/>
</xsl:for-each-group>
</xsl:template>
<xsl:template name="states">
<xsl:variable name="index" select="@index"/>
<states>
<xsl:for-each select="current-group()">
<name>
<xsl:value-of select="@sname"/>
</name>
</xsl:for-each>
</states>
</xsl:template>
I get the desired result in Oxygen -
<Country>
<CountryInfo>
<name>Country Name: United Sates of America</name>
<districts>50</districts>
<states>
<name>New York</name>
<name>Chicago</name>
</states>
</CountryInfo>
<CountryInfo>
<name>Country Name: Germany</name>
<districts>16</districts>
<states>
<name>Berlin</name>
<name>Brandenburg</name>
</states>
</CountryInfo>
</Country>
In an Oracle Transform I get a "XPath expression failed to execute" error. I narrowed down the cause of the error. The error is caused by
the nested for-each-group using "current-group()."
<xsl:for-each-group select="current-group()" group-by="@index">
<xsl:call-template name="states"/>
</xsl:for-each-group>
Oracle does not throw an error if I use "Country/info" instead of "current-group()," but this does not produce the desired result
because it needs to be grouped by "@index."
Does anyone know why my XSLT does not work in an Oracle Transform?