sorting within current-group()
Hi,
This is my first question (post) in this forum, I wish to sort the <cityNames> within the <record> element. Is there any way to sort?
Input:
<cities>
<cityName>Barodara</cityName>
<cityName>Ahemadabad</cityName>
<stateName>Gujrat</stateName>
<cityName>Varanasi</cityName>
<cityName>Allahabad</cityName>
<stateName>Uttar Pradesh</stateName>
<cityName>Hyderabad</cityName>
<cityName>Bangalore</cityName>
<stateName>Andhara Pradesh</stateName>
</cities>
XSL Code:
<xsl:template match="cities">
<xsl:copy-of select="rit:cit(./*)"/>
</xsl:template>
<xsl:function name="rit:cit" as="item()*">
<xsl:param name="ct" as="node()*"/>
<xsl:element name="root">
<xsl:for-each-group select="$ct" group-ending-with="stateName">
<xsl:element name="record">
<xsl:copy-of select="current-group()"/>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:function>
Current Output:
<root>
<record>
<cityName>Barodara</cityName>
<cityName>Ahemadabad</cityName>
<stateName>Gujrat</stateName>
</record>
<record>
<cityName>Varanasi</cityName>
<cityName>Allahabad</cityName>
<stateName>Uttar Pradesh</stateName>
</record>
<record>
<cityName>Hyderabad</cityName>
<cityName>Bangalore</cityName>
<stateName>Andhara Pradesh</stateName>
</record>
</root>
Expected Output:
<root>
<record>
<cityName>Ahemadabad</cityName>
<cityName>Barodara</cityName>
<stateName>Gujrat</stateName>
</record>
<record>
<cityName>Allahabad</cityName>
<cityName>Varanasi</cityName>
<stateName>Uttar Pradesh</stateName>
</record>
<record>
<cityName>Bangalore</cityName>
<cityName>Hyderabad</cityName>
<stateName>Andhara Pradesh</stateName>
</record>
</root>
thanks!
|