generate-id for copy

Subject: generate-id for copy
From: Andrew Wason <aw@xxxxxxxxxxx>
Date: Mon, 17 Jan 2000 15:28:19 -0500
I want to copy a node in my source multiple times and assign each copy a unique id attribute. generate-id is generating an ID for the context node which is the same for each copy. Is there some way have generate-id operate on the newly copied node to get a unique ID for each copy?

Here is my input document:

<root>
	<node attr="myattr"/>
</root>


Here is my stylesheet:



<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";> <xsl:output method="xml" indent="yes"/>

	<xsl:template match="node">
		<xsl:apply-templates select="." mode="duplicate-node"/>
		<xsl:apply-templates select="." mode="duplicate-node"/>
		<xsl:apply-templates select="." mode="duplicate-node"/>
		<xsl:apply-templates select="." mode="duplicate-node"/>
	</xsl:template>

	<xsl:template match="*" mode="duplicate-node">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:attribute name="id">
				<xsl:value-of select="generate-id()"/>
			</xsl:attribute>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>


Here is the output:


<node attr="myattr" id="doc2ab9"></node>
<node attr="myattr" id="doc2ab9"></node>
<node attr="myattr" id="doc2ab9"></node>
<node attr="myattr" id="doc2ab9"></node>


Thanks, Andrew -- Andrew Wason softcom aw@xxxxxxxxxxx


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread