Subject: RE: [xsl] Check for duplicate @id's - collection() From: "Philip Vallone" <philip.vallone@xxxxxxxxxxx> Date: Sat, 19 Jul 2008 12:09:59 -0400 |
Thank you Ken, This is a great idea which I currently use the following template for: <xsl:template name="get-mandatory-id"> <xsl:param name="id-val"/> <xsl:choose> <xsl:when test="string-length($id-val) > 0"> <xsl:value-of select="$id-val"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="generate-id()"/> </xsl:otherwise> </xsl:choose> </xsl:template> However, I also use some of the IDs for cross-referencing for PDF output and HTML. So generating the id dynamicly is something I can't always do, unless I am missing the obvious? Regards, Phil -----Original Message----- From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx] Sent: Saturday, July 19, 2008 11:45 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Check for duplicate @id's - collection() At 2008-07-19 11:28 -0400, Philip Vallone wrote: >I have a project were I take about 800 files and transform them into >one .fo document (create a pdf). The files are authored independent of >each other (stand alone) which are validated against a schema >(independently). If there is a duplicate @id attribute, the validator >will tell me. However, the @ids need to be unique across all files >processed by the collection function. If they are not, my resulting .fo >will have duplicate @ids, which cause FOP to halt. This is the use case for generate-id() ... in my XSL classes I take the students through the two steps of ensuring unique identifiers in aggregating XML source documents to a single XSL-FO result document: Assuming the current node is the element with the @id attribute, the unique anchor in the FO tree is created using something along the lines of: <block id="{generate-id(.)}"> Assuming you are at the element that is making the reference with @idref and you have a DTD declaration for the ID property of the target element, the link is created using: <basic-link internal-destination="{generate-id(id(@idref))}"> ... or you can just move your context to the element with the @id attribute and do: <basic-link internal-destination="{generate-id(.)}"> >I am looking for a way to (query or xslt 2.0) to check for duplicate >@id's values across all files with the collection function. This would >be a pre-production check. Not needed if you choose to use generate-id() ... it is specified to guarantee uniqueness across all nodes when it is called for any node in the node tree, and within one run of the stylesheet you always get the same value returned for any given node. It is an opaque value, alpha-numeric, that you use without analyzing its value because every processor will give you something different ... but you can add your own ".","-" or "_" character to it if you need to make multiple unique anchors for one node. The value is not guaranteed to be the same the next time you run the stylesheet on the node tree, even if the node tree is unchanged. The value cannot be reliably sorted or relied on for any purpose other than being unique. By using generate-id() you never need to worry which values are being used by your authors, provided within each XML file they are being used properly. I hope this helps. . . . . . . . . . . Ken -- Upcoming XSLT/XSL-FO hands-on courses: Wellington, NZ 2009-01 World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Check for duplicate @id', G. Ken Holman | Thread | RE: [xsl] Check for duplicate @id', G. Ken Holman |
Re: [xsl] Check for duplicate @id', Vladimir Nesterovsky | Date | RE: [xsl] Check for duplicate @id', G. Ken Holman |
Month |