Subject:Creating hierarchical identifier attributes Author:Joseph Greene Date:29 Jun 2007 09:16 AM
Hello,
I am trying to automate the creaton of a unitid/@identifier at each item
level entry in a hierarchy. I will ultimately insert the values using eXist XML database via eXist's XQuery update extensions. They are simply a concatenation of all the //did/unitid ancestors of each item.
I cannot for the life of me figure a way to create these identifiers,
using XSLT or XQuery. I feel as though there should be SOME set of rules
to create these, as they are quite logical:
In an archive, such as the following,
I Papers of Joe Bloggs
A His childhood
i Pictures
1 A picture Joe drew age 4
2 Another picture
3 A letter to Santa
4 Something else
etc.
Where the Arabic numerals represent items,
I would like a list of unitid/@identifiers such as this:
I Papers of Joe Bloggs
A His childhood
i Pictures
1 A picture Joe drew age 4 (I-A-i:1)
2 Another picture (I-A-i:2)
3 A letter to Santa (I-A:3)
4 Something else (I-A:4)
Getting them into the EAD XML document will be the 'easy' part, so any help on this side of the equation would be most appreciated, whether Xquery or XSLT (or Perl suggestions for that matter).
Following is what the outcome should look like, in EAD XML:
<dsc>
<c01 level="series">
<did>
<unitid>I</unitid>
<unittitle>Life and times of Joe Bloggs</unittitle>
</did>
<c02 level="subseries">
<did>
<unitid>A</unitid>
<unittitle>His childhood</unittitle>
</did>
<c03 level="subseries">
<did>
<unitid>i</unitid>
<unittitle>Pictures</unittitle>
</did>
<c04 level="item">
<did>
<unitid identifier="I-A-i:1">1</unitid>
<unittitle>A picture Joe drew age 4</unittitle>
</did>
</c04>
<c04 level="item">
<did>
<unitid identifier="I-A-i:2">2</unitid>
<unittitle>Another picture</unittitle>
</did>
</c04>
</c03>
<c03 level="item">
<did>
<unitid identifier="I-A:3">3</unitid>
<unittitle>A letter to Santa</unittitle>
</did>
</c03>
<c03 level="item">
<did>
<unitid identifier="I-A:4">4</unitid>
<unittitle>Something else</unittitle>
</did>
</c03>
</c02>
</c01>
</dsc>
Any ideas?
Joseph Greene
Irish Virtual Research Library and Archive Project (HII),
James Joyce Library,
UCD,
Belfield,
Dublin 4.
Subject:Creating hierarchical identifier attributes Author:Tony Lavinio Date:29 Jun 2007 10:24 AM
This is the Stylus Studio support forum, and we don't recognize
your email address as one belonging to a registered user (even of
an evaluation copy). Could you please tell us which version you
are using before we proceed?
declare function local:generateID($node as element()) as xs:string
{
(: locate the previous unitid: the parent of $node is a <did>,
it's parent is my <cXX>, it's parent is the parent <cXX>
or <dsc> :)
let $parentChapter := $node/../../.. ,
$value := $node/text()
return
(: if we found <dsc> we are the first one, return just the content :)
if(local-name($parentChapter)='dsc') then
$value
else
(: if the value is a number, precede it with ':', otherwise with '-' :)
if($value castable as xs:integer) then
fn:concat(local:generateID($parentChapter/did/unitid), ':', $value)
else
fn:concat(local:generateID($parentChapter/did/unitid), '-', $value)
};
for $unit in //unitid
return
<unitid identifier="{local:generateID($unit)}">{$unit/text()}</unitid>
Thanks, Alberto. I've never built any functions with XQuery, but it seems like the way to go, a good middle ground between XPath and Perl. I'll have a look at this logic and see how it goes; it's certainly a new approach to the problem, which I was short of!