I feel its not possible with pure XSLT 1.0 . We need
to take help of extension function (node-set). Below
is the solution..
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" xmlns:exslt="http://exslt.org/common"
exclude-result-prefixes="exslt">
<xsl:output method="xml" indent="yes" />
<xsl:key name="by-desc" match="b"
use="concatenated-desc" />
<xsl:template match="/a">
<xsl:variable name="rtf">
<a>
<xsl:for-each select="b">
<b>
<concatenated-desc>
<xsl:call-template
name="concatenate-desc">
<xsl:with-param name="x"
select=".//desc" />
<xsl:with-param name="y" select="''" />
</xsl:call-template>
</concatenated-desc>
<xsl:copy-of select="child::node()" />
</b>
</xsl:for-each>
</a>
</xsl:variable>
<a>
<xsl:for-each
select="exslt:node-set($rtf)/a/b[generate-id(.) =
generate-id(key('by-desc',concatenated-desc)[1])]">
<group-of-b>
<xsl:for-each
select="key('by-desc',concatenated-desc)">
<b>
<xsl:copy-of
select="child::node()[not(self::concatenated-desc)]"
/>
</b>
</xsl:for-each>
</group-of-b>
</xsl:for-each>
</a>
</xsl:template>
<xsl:template name="concatenate-desc">
<xsl:param name="x" />
<xsl:param name="y" />
<xsl:choose>
<xsl:when test="count($x) > 0">
<xsl:call-template name="concatenate-desc">
<xsl:with-param name="x" select="$x[position()
> 1]" />
<xsl:with-param name="y"
select="concat($y,normalize-space($x[1]))" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$y" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
For e.g. when the above XSL is applied to XML -
<a>
<b>
<desc>some text
</desc>
<bChild>
<desc>some other text
</desc>
</bChild>
</b>
<b>
<desc>some text
</desc>
<bChild>
<desc>some other text
</desc>
</bChild>
<bChild>
<desc>maybe some more text
</desc>
</bChild>
</b>
<b>
<desc>some text
</desc>
<bChild>
<desc>some other text
</desc>
</bChild>
<test>xyz</test>
</b>
</a>
The output recieved is -
<?xml version="1.0" encoding="UTF-8"?>
<a>
<group-of-b>
<b>
<desc>some text
</desc>
<bChild>
<desc>some other text
</desc>
</bChild>
</b>
<b>
<desc>some text
</desc>
<bChild>
<desc>some other text
</desc>
</bChild>
<test>xyz</test>
</b>
</group-of-b>
<group-of-b>
<b>
<desc>some text
</desc>
<bChild>
<desc>some other text
</desc>
</bChild>
<bChild>
<desc>maybe some more text
</desc>
</bChild>
</b>
</group-of-b>
</a>
Regards,
Mukul
--- Edmund Mitchell <emitchell(_at_)emn8(_dot_)com> wrote:
So b elements can have description children (desc),
and so can their bChild
children.
The goal is to Meunchian group all the b elements on
the concatenated value
of their desc and the desc values of however many
bChild children there are.
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
--~------------------------------------------------------------------
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>
--~--