Subject:Generating unique ID in whole tree Author:dorian dinh Date:28 Oct 2006 12:46 PM
Hello there,
i need to input a xmi:id attribute in every element of a xml document. If the attribute already exists, i don't generate it. In the other hand, when i generate one, its value must be different from those existing.
For the first part its done. For the second part i tried to help myself with a old post of micheal kay. But it doesn't work.
He doesn't seem to understand :
<xsl:key name="k" match="child::node()[@xmi:id]" use="@xmi:id"/>
(no error at compiling but my test fails)
Subject:Generating unique ID in whole tree Author:dorian dinh Date:28 Oct 2006 10:09 PM
hmm... found the error :
<xsl:key name="id-table" match="*[@xmi:id]" use="@xmi:id"/>
... still don't understand difference between those expressions :
child::node()[@xmi:id]
child::*[@xmi:id]
otherwise i don't understand why this expression :
descendant::*[@xmi:id] can't be built. i tried to use this because "child" should only take direct children of my context not all descendant children... and my id-table should consider whole element in my tree.
Subject:Generating unique ID in whole tree Author:Ivan Pedruzzi Date:29 Oct 2006 01:30 PM
Hi Dorian,
The pattern in the match attribute of xsl:key element can be a relative expression because the context of a key is established where they key is invoked so @xmi:id is a perfectly acceptable pattern.
child::* matches only elements while child:nodes() matches any type of node therefore if you are lookig an attribute in the predicate to want to use *.
Only 'child' and 'attribute' axes are allowed in a match pattern outside predicates.
Subject:Generating unique ID in whole tree Author:dorian dinh Date:29 Oct 2006 02:00 PM
your solution doesnt work.
1) need recursive calling template make-id in case "<kind of id>ï" already exists so as to make "<kind of id>ïï...ï"
2) need to make an access to precedant child.