[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] improving performance in creating ids
Hi All,
I need generated-ids on elements in a BITS file that have @rids, so I can link back to them. I cannot use generate-id(), because I need it to produce the same id in both the xquery (eXist) context and in the XSL (saxon) contect. I have created a function that will generate a human readable id based on the id of the nearest ancestor/@id and then element-name + sequence number. It produces the output that I like, but at the cost of a poor performance (when run on a whole book) . now with the preceding/ancestor juggling that I do there might be a better way than mine, so my question is if there is a better way to tackle this problem. My function: declare function local:get-id-in-doc ( $target as element() ) as xs:string { B let $current-element as xs:string := local-name($target) B let $ancestor-with-id as element()? := $target/ancestor::*[@id][1] B let $prefix as xs:string? := $ancestor-with-id/@id/string() B let $count := B B B if($prefix) then B B B B B (: case 1: there is an ancestor with an @id :) B B B B B count($target/preceding::*[local-name() eq $current-element][ancestor::* = $ancestor-with-id]) + 1 B B B else if ( count($target/ancestor-or-self::*[local-name() eq $current-element]) eq 1) then B B B B B (: case 2: no numbering needed :) B B B B B () B B B else B B B B B (: case 3: numbering based on position in the whole document :) B B B B B count($target/preceding::*[local-name() eq $current-element]) + 1 B let $numbered-id as xs:string := concat(replace($prefix,'\.','-'), if($prefix) then '-' else (), $current-element, $count) B return $numbered-id }; My questions: 1. Is there a better way to look up the number of preceding same-named elements in a subset of a document that is defined by the @id on some ancestor? 2. Is there an alternative way of generating ids (possibly having less human-readable values) that would work in both the xquery and xslt realm? Thanks. -- Pieter Lamers John Benjamins Publishing Company Postal Address: P.O. Box 36224, 1020 ME AMSTERDAM, The Netherlands Visiting Address: Klaprozenweg 75G, 1033 NN AMSTERDAM, The Netherlands Warehouse: Kelvinstraat 11-13, 1446 TK PURMEREND, The Netherlands tel: +31 20 630 4747 web: www.benjamins.com
|
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
|