[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Assigning unique id to new node using generate-id()

Subject: Assigning unique id to new node using generate-id()
From: <kyle.himmerick@xxxxxxxxxxxxxx>
Date: Wed, 13 Aug 2003 12:11:53 -0400 (EDT)
xsl unique id
I'm having unexpected results with the generate-id() function.

I am attempting to add a new node to an existing document and assigning a new and
*unique* id attribute to the new node.

Sample XML:
<profile>
<credential id="N400012">
		<username><![CDATA[user1]]></username>
		<password><![CDATA[pass1]]></password>
		<description><![CDATA[my description]]></description>
		<lastModified>2003-08-07 14:19:13</lastModified>
	</credential>
	<credential id="N40002B">
		<username><![CDATA[user2]]></username>
		<password><![CDATA[pass2]]></password>
		<description><![CDATA[another id]]></description>
		<lastModified>2003-08-06 16:03:52</lastModified>
	</credential>
</profile>

I'd like this stylesheet to copy all existing credential nodes and create a new
node assigning a unique id with generate-id().  It appears as if the generate-id
call doesn't observe existing id's in the current/copied credential nodes.  So I
end up with duplicate (illegal) id's.  I've tried passing several context nodes
to the generate-id() function, but with no luck.

Sample XSL:
	<xsl:template match="/profile">
		<profile>
			<xsl:for-each select="credential">
				<xsl:copy-of select="."/>
			</xsl:for-each>
			<credential>
				<xsl:attribute name="id">
					<xsl:value-of select="generate-id()"/>
				</xsl:attribute>
				<username><xsl:value-of select="$username"/></username>
				<password><xsl:value-of select="$password"/></password>
				<description><xsl:value-of select="$description"/></description>
				<lastModified><xsl:value-of
select="java:getCurrentDateTimeGMT($dateHelper)"/></lastModified>
			</credential>
		</profile>
	</xsl:template>

My current workaround is to transform twice.  The first transformation appends
the new credential node.  The second transformation assigns an id (using
generate-id()) to any credential nodes without an id (probably only newly
created).  Seems like I should be able to do it all in one transform.

Thanks for your help.



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.