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

RE: question about generate-id()

Subject: RE: question about generate-id()
From: "Mario Madunic" <Mario_Madunic@xxxxxxxxxxxx>
Date: Thu, 5 Aug 2010 06:03:50 -0500
RE:  question about generate-id()
Thought I'd throw this one out for unique IDs using generate-id(). I usually
use something like the following

<anelement id="{concat(generate-id(), '-', local-name(), '-',
count(preceding::*))}"> ...</>

And if you want you can add the docs name to the ID value also. I usually do
this as this gives unique IDs across files.

If by chance you have any illegal chars in the ID value then just translate()
them out.

Hope this helps.

Marijan (Mario) Madunic
Publishing Specialist
New Flyer Industries

-----Original Message-----
From: Tony Graham [mailto:Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx]
Sent: Thursday, August 05, 2010 4:11 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  question about generate-id()

On Thu, August 5, 2010 7:49 am, Dave Pawson wrote:
> On Wed, 04 Aug 2010 18:18:40 -0400
> "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
>
>> The uniqueness of identifiers is guaranteed only when generate-id()
>> is used for every identifier.  This makes sense because generate-id()
>> has no way of knowing which of your attributes are identifiers and
>> which are not.
>
> Not even when the 'id' values are @id? That sounds wrong Ken.

Possibly not everybody uses @id to mean an ID, plus there's plenty of
other attributes, such as @name, that may or may not be IDs.  The only
attribute that is guaranteed to be an ID is @xml:id, and that postdates
XSLT 1.0 by about six years.

> 16.6.4
> There is no guarantee that a generated unique identifier will be
> distinct from any unique IDs specified in the source document.
>
> Yuk. IMHO that's a spec weakness. More constrained, surely
> it's not rocket science to implement.

You could do it yourself with keys and a bit of checking, but in the
general case, not everybody will need to search a possibly large source
document in the off-chance that a duplicate ID will be generated (though
if you keep using the same XSLT processor over slightly modified versions
of the same source document, you do stand a good chance of creating
duplicates.)

In this brave new world of streaming XSLT, you might not see the existing
ID value until after you've generated what would be a duplicate ID.

The earlier idea of adding a timestamp to the generated ID, or even a
known prefix if you do things in fixed phases, would be less overhead than
avoiding existing IDs.  I've also implemented a uuid() extension function
for a client to guarantee that generated IDs are unique.

Regards,


Tony Graham                         Tony.Graham@xxxxxxxxxxxxxxxxxxxxxx
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


--------------------------------------------------------------------
Please consider the environment before printing this e-mail.

CONFIDENTIALITY STATEMENT: This communication (and  any and all information or
material transmitted with this communication) is confidential, may be
privileged and is intended only for the use of the intended recipient. If you
are not the intended recipient, any review, retransmission, circulation,
distribution, reproduction, conversion to hard copy, copying or other use of
this communication, information or material is strictly prohibited and may be
illegal. If you received this communication in error or if it is forwarded to
you without the express authorization of New Flyer, please notify us
immediately by telephone or by return email and permanently delete the
communication, information and material from any computer, disk drive,
diskette or other storage device or media. Thank you.

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.