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

Re: Assigning unique id to new node using generate-id(

Subject: Re: Assigning unique id to new node using generate-id()
From: <kyle.himmerick@xxxxxxxxxxxxxx>
Date: Wed, 13 Aug 2003 15:47:01 -0400 (EDT)
xsl generate unique id
Thanks for all of your feedback.  I've got a solution that will meet my requirements.

I've added a nextCredentialID attribute to the users profile.  This will serve as
a counter, that I will update each time I add a new credential (but won't change
when I edit or delete a credential).

Then for the credentialID of the new node, I prefix with a 'c' so it's a valid
xml ID attribute.

Below is the sylesheet I'm using to add a new credential.

    <xsl:template match="/profile">
        <profile>
            <xsl:attribute name="nextCredentialID">
                <xsl:value-of select="number(@nextCredentialID) + number('1')"/>
            </xsl:attribute>
            <xsl:for-each select="credential">
                <xsl:copy-of select="."/>
            </xsl:for-each>
            <credential>
                <xsl:attribute name="id">
                    <xsl:value-of select="concat('c', @nextCredentialID)"/>
                </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>
    </xsl:template>

Thanks again for your help.
Kyle

On Wed, 13 Aug 2003 17:57 , David Carlisle <davidc@xxxxxxxxx> sent:

>
>> It appears as if the generate-id
>> call doesn't observe existing id's in the current/copied credential nodes. 
>
>that is so, the only thing generate-id() is defined to do is 
>return a unique string that matches the Name production (so is usable as
>an id) when applied to any node in the source. 
>
>> 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.
>
>That doesn't sound a safe workaround. You have no assurance that the ids
>generated on the second pass won't be teh same as an existing id in your
>source.
>
>If you don't need the ids to be stable you could of course regenerate
>the document wioth new ids in each case, generated by generate-id() they
>would all then be distinct but also typically didffernt from teh id in
>teh source.
>
>Otherwise you need a different way to generate unique id. Two obvious contenders.
>As your are always adding to teh doc you coul duse
>
>
>
>...
>
>so the id will be id followed by teh number of elements you had before,
>this will go up by one each time,
>
>or you could use
>
>':- ','')}">
>
>an use an id based on the current time.
>
>David
>
>________________________________________________________________________
>This e-mail has been scanned for all viruses by Star Internet. The
>service is powered by MessageLabs. For more information on a proactive
>anti-virus service working around the clock, around the globe, visit:
>http://www.star.net.uk
>________________________________________________________________________
>
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>





 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.