is this possible

Is it possible to insert a auto generated id whit xquery like this

  update insert attribute id {generate-id(.)}
into input()//p


Or is there a nothere way to make auto generated id whit xquery?

Hi DBB,

I am not really understanding what you intend to do here, but Tamino does offer functions to get something like a node identification from a persistent node. This id is a pair of the docid and a node id that is unique within a document. Unfortunately (from your point of view) only one of these can be obtained by legal Tamino functions: getInoId(node) gets the InoId of a node’s document. The function to obtain the node id is currently only internally available (we need that for update). We did not officially document this function, since this would raise lots of questions like how persistent this node id is, what happens if nodes from the doument are added/deleted, etc. So the answer to your question is ‘no you can’t do that’, but it would interest me what you have in mind since this issue is still rather open.

To answer our question not w.r.t. Tamino but the W3C’s XQuery standard; there the answer is also no, i.e. there is no concept yet of producing a consistent node id. There is however something like a node id in that there is something called node comparison that says :
‘A comparison with the is operator is true if the two operands are nodes that have the same identity’,
see http://www.w3.org/TR/xquery/#id-node-comparisons.

Regards,
Juliane.

Sorry for not explaining it better in my first post :slight_smile:

What I intended to do was whit this xquery

  update insert attribute id {generate-id(.)}
into input()//p </pre><BR>was to generate a id and update all my documents node p whit a unik id <BR>I was wondering if it was possible to use the generate-id(.) function whit a update.<BR><BR>also I am wondering about this xquery<BR><pre class="ip-ubbcode-code-pre"> declare namespace tf = 'http://namespaces.softwareag.com/tamino/TaminoFunction'
declare namespace ft = 'http://www.w3.org/2002/04/xquery-operators-text'
declare namespace xs = 'http://www.w3.org/2001/XMLSchema' 

for $bib in input()/dtbook 
let $x:=$bib//p
let $z := 
	for $y in $x  
	where ft:text-contains($y, 'java')
	return  $y  
where $z  
return <book> 
{ 
	attribute inoId{tf:getInoId($bib)}, 
	attribute docname{tf:getDocname(root($bib))}, 
	attribute matchCount{count($z)}, 
	<title>{ 
	attribute title{$bib/head/title} 
	}</title>, 
	<chapter>
	{ 		
		for $f in $z/parent::level1/h1 
		let $h :=
			for $g in $f/parent::*//p
			where ft:text-contains($g, 'java')
			return $g 
			
		return 	<heading>
		{
			attribute matchCountP
			{
				count($h)
			},
			attribute ID{$z/parent::*/@id},
			$f/text()
		}		
		</heading>
		sort by( xs:int(@matchCountP) descending)	
	}</chapter> 
}</book>
sort by( xs:int(@matchCount) descending) 



I here get returned for $z/parent::level1/h1 node but I would also like to do it to for $z/parent::level2/h2 nodes at the same time how would I do that as I cant use the name()=h1 in xquery what would I use insted of name()=h1???
Hope this was easyer to understand and thank for your answare.

I’m having a bit of trouble following this, partly because I’m not sure what your source documents look like.

generate-id() is an XSLT function that isn’t available in XPath or XQuery. I guess you’re looking for something that’s functionally equivalent, i.e. that generates a unique identifier for any node in the database?

I’m not sure why you think you can’t use [name()=‘h1’] in XQuery. But usually, using [self::h1] is preferable, because it’s less sensitive to namespace prefixes, and may be more optimizable. I’m not sure where you actually want to use this test. If it’s here:

for $f in $z/parent::level1/h1

then you could write

for $g in ($z/parent::level1/h1 | $z/parent::level2/h2)

but perhaps I’ve misunderstood your requirement.

Michael Kay

Thanks Michael Kay the self:: was defently the one to use It now works But when I used name()=h1 I got back from tamino that it did not know name function so that was why I couldent use that one. But again thanks for your help this made me go along way :slight_smile:

also when it comes to

 generate-id() is an XSLT function that isn't available in XPath or XQuery. I guess you're looking for something that's functionally equivalent, i.e. that generates a unique identifier for any node in the database? 


that is ecaxtly what I am looking for is there a way to do this by xquery or do I have to do it by C# or a xslt

[This message was edited by DBB on 09 Jul 2003 at 10:12.]

No, unfortunately XQuery doesn’t offer any equivalent to XSLT’s generate-id(). I think it would be quite hard to get this through the standards process because of all the questions about the persistence of the identifier. But when updates are added in version 2.0, the language will probably need something like this. Meanwhile, as Juliane mentioned, we are having our own thoughts about how to meet this requirement in a Tamino-specific way.

Michael Kay