Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Error using nested for-each-group in Oracle XSLT

oracleisthewayMay 28 2013 — edited May 28 2013
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?
This post has been answered by odie_63 on May 28 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 25 2013
Added on May 28 2013
2 comments
2,239 views