XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + Issue with Processing Instruct... (2)
-> + problem converting json to XML... (2)
-> + Problem base64 decoding string... (3)
-> + Problems posting multipart for... (5)
-> + trouble with download of price... (2)
-> + Problem with http-post not bei... (3)
-> + path problem, xps_file:writeAl... (9)
-> + Xquery update support? (2)
-> + problem with Stylus studio try... (5)
-> + adding dtd reference to xml ou... (4)
-> + xquery escaping ambarsand when... (3)
-> + Whitespace problem when return... (5)
-> + Problem with namespace prefix ... (5)
-> - Sending via SFTP returns unexp... (1)
-> + Query and Sftp clent (4)
-> + xquery and try - catch (3)
-> + Query + ddtek:http-post optio... (5)
-> + Example files referenced in do... (3)
-> + Automatic Error Detection and ... (3)
-> + Working with result of ddtek:h... (2)
-- [1-20] [21-40] [41-60] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Joseph GreeneSubject: 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:

<identifier>I-A-i:1</identifier>
<identifier>I-A-i:2</identifier>
<identifier>I-A:3</identifier>
<identifier>I-A:4</identifier>

So with the code in ():

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.

(t) 01 716 7506
(e) joseph.greene@ucd.ie
(w) www.ucd.ie/ivrla

Postnext
Tony LavinioSubject: 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?

Postnext
Joseph GreeneSubject: Creating hierarchical identifier attributes
Author: Joseph Greene
Date: 02 Jul 2007 04:51 AM
Hello,

I'm using Stylus Studio 2007 XML Enterprise Release 2.

JG

Postnext
(Deleted User) Subject: Creating hierarchical identifier attributes
Author: (Deleted User)
Date: 02 Jul 2007 08:16 AM
Hi Joseph,
something like this should work

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>

Hope this helps,
Alberto

Posttop
Joseph GreeneSubject: Creating hierarchical identifier attributes
Author: Joseph Greene
Date: 04 Jul 2007 07:23 AM
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!

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.