On Thursday 20 November 2003 13:28, Ram wrote:
Hi,
Can anyone please give me hint how to copy the previous
operations? Actually, the input xml file is a dynamic one and
the number of 'group' is arbitrary. The xml source would look
like this:
Cut ...
While on the surface this looks like something you could solve
using recursion and preceding searches your XML would allow the
groups to appear in any order since each contains a direct
reference to the group that should be used to replace the
signature. In this case the replacing signature could appear
either before or after the group you are processing. These types
of operations are normally easier to handle by introducing a key
such as,
<xsl:key name="GroupByIdentifier" match="group"
use="identifier[1]"/>
You can then process using a modified identity transform,
something like this should work,
<xsl:template match="signature">
<xsl:choose>
<xsl:when test="count(../identifier[2])>0">
<xsl:apply-templates
select="key("GroupByIdentifier",../identifier[2])/signature"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
This isn't the most efficient implemetation you could create but
for small to medium sized number of groups it should be
sufficient.
Regards,
Kev.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list