[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()
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|