Discussion:
generate-id() problem
Nima Kaviani
2006-11-24 08:37:53 UTC
Permalink
Hi all,

I have a problem with using generate-id()

apparantly, as I see it in my code, generate-id is dependent to the
context and the current location in the xml document. that is, when I
use generate-id() twice and in the same context it returns the same
value though I need two different values!

however, when I use generate-id(../..) or generate-id(/) it returns
some other values to me!

is there anything wrong with my settings and assumptions? do I have
any way around it?

thanks,
-Nima

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Colin Paul Adams
2006-11-24 09:13:10 UTC
Permalink
Nima> Hi all, I have a problem with using generate-id()

Nima> apparantly, as I see it in my code, generate-id is dependent
Nima> to the context and the current location in the xml
Nima> document. that is, when I use generate-id() twice and in the
Nima> same context it returns the same value though I need two
Nima> different values!

Then don't use generate-id().

Nima> however, when I use generate-id(../..) or generate-id(/) it
Nima> returns some other values to me!

Nima> is there anything wrong with my settings and assumptions? do
Nima> I have any way around it?

I think it is your understanding of generate-id().

It uniquely identifies the node passed as it's argument (or the
context node, if it has no argument).
--
Colin Adams
Preston Lancashire

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Michael Kay
2006-11-24 09:15:09 UTC
Permalink
generate-id() with no parameters is equivalent to generate-id(.) - it
returns the identifier of the context node. If you call it twice with the
same argument, it is guaranteed to return the same answer.

You seem to be in need of a completely different function, so you need to
explain what you are trying to do.

Michael Kay
http://www.saxonica.com/
-----Original Message-----
On Behalf Of Nima Kaviani
Sent: 24 November 2006 08:38
Subject: [xsl] generate-id() problem
Hi all,
I have a problem with using generate-id()
apparantly, as I see it in my code, generate-id is dependent
to the context and the current location in the xml document.
that is, when I use generate-id() twice and in the same
context it returns the same value though I need two different values!
however, when I use generate-id(../..) or generate-id(/) it
returns some other values to me!
is there anything wrong with my settings and assumptions? do
I have any way around it?
thanks,
-Nima
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Nima Kaviani
2006-11-24 09:59:31 UTC
Permalink
ok sorry about the confusion I made. what I need to do is to generate
a unique identifier for different nodes. so I need to generate an XML
of the form below

<rule:foo rdf:ID="rule_N2320">
<rule:bar rdf:resource="constraint_N3456"/>
</rule:foo>

<constraint:test rdf:ID="constraint_N3456">
<t1/>
<t2/>
<constraint:tes>

ok so as it is obvious in the code above, I need to generate two
unique values, here "N2320" and "N3456", using a funciton and attach
them to my terms, "rule" and "constraint".

I need to generate these two numbers at the same time in my xslt
template as I need to keep track of the generated elements and their
ids later in the code. I thought of generate-id() as the suitable
function for my purpose. In one of the tutorials I read on XSLT it
says that generate-id() can be used to generate a unique string for a
node, so based on this single line hint, I thought that would be what
I need but apparantly it isn't.

thanks in advance for the help,
-Nima
Post by Michael Kay
generate-id() with no parameters is equivalent to generate-id(.) - it
returns the identifier of the context node. If you call it twice with the
same argument, it is guaranteed to return the same answer.
You seem to be in need of a completely different function, so you need to
explain what you are trying to do.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
On Behalf Of Nima Kaviani
Sent: 24 November 2006 08:38
Subject: [xsl] generate-id() problem
Hi all,
I have a problem with using generate-id()
apparantly, as I see it in my code, generate-id is dependent
to the context and the current location in the xml document.
that is, when I use generate-id() twice and in the same
context it returns the same value though I need two different values!
however, when I use generate-id(../..) or generate-id(/) it
returns some other values to me!
is there anything wrong with my settings and assumptions? do
I have any way around it?
thanks,
-Nima
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Florent Georges
2006-11-24 12:53:50 UTC
Permalink
Nima Kaviani wrote:

Hi
Post by Nima Kaviani
<rule:foo rdf:ID="rule_N2320">
<rule:bar rdf:resource="constraint_N3456"/>
</rule:foo>
<constraint:test rdf:ID="constraint_N3456">
<t1/>
<t2/>
<constraint:tes>
ok so as it is obvious in the code above, I need to
generate two unique values, here "N2320" and "N3456",
using a funciton and attach them to my terms, "rule" and
"constraint".
So you can use generate-id() iff you can make a link
between these generated elements and nodes in your input
tree. For example, say that those elements are generated in
the template for the element "myelem", that have a mandatory
attribute "myattr". Then you can write:

<xsl:template match="myelem">
<!-- Will always generate the same string for the same
myelem node in the same transformation. -->
<rule:foo rdf:ID="rule_{ generate-id(.) }">
...
</rule:foo>
<!-- Will always generate the same string for the same
@myattr node in the same transformation. -->
<constraint:test
rdf:ID="constraint_{ generate-id(@myattr) }">
..
<constraint:tes>
</xsl:template>

Regards,

--drkm























___________________________________________________________________________
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Nima Kaviani
2006-11-25 21:59:58 UTC
Permalink
Hi Florent,

thanks for the msg. However your used syntax ( <rule:foo
rdf:ID="rule_{ generate-id(.) }">) is not working for me. My xalan
XSLT Processor complains about the use of curly braces in the string.
So I have to use it this way: <rule:foo rdf:ID="concat('rule_',
generate-id(.))">

ok I guess at this point it doesn't really matter. I just mentioned it
to check whether this is a problem at the level of the processor or
something else.

thanks for the idea you gave to me. It helps to generate unique ids.

-Nima
Post by Florent Georges
Hi
Post by Nima Kaviani
<rule:foo rdf:ID="rule_N2320">
<rule:bar rdf:resource="constraint_N3456"/>
</rule:foo>
<constraint:test rdf:ID="constraint_N3456">
<t1/>
<t2/>
<constraint:tes>
ok so as it is obvious in the code above, I need to
generate two unique values, here "N2320" and "N3456",
using a funciton and attach them to my terms, "rule" and
"constraint".
So you can use generate-id() iff you can make a link
between these generated elements and nodes in your input
tree. For example, say that those elements are generated in
the template for the element "myelem", that have a mandatory
<xsl:template match="myelem">
<!-- Will always generate the same string for the same
myelem node in the same transformation. -->
<rule:foo rdf:ID="rule_{ generate-id(.) }">
...
</rule:foo>
<!-- Will always generate the same string for the same
@myattr node in the same transformation. -->
<constraint:test
..
<constraint:tes>
</xsl:template>
Regards,
--drkm
___________________________________________________________________________
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--
Florent Georges
2006-11-26 14:11:35 UTC
Permalink
Nima Kaviani wrote:

Hi
My xalan XSLT Processor complains about the use of curly
<rule:foo rdf:ID="concat('rule_', generate-id(.))">
ok I guess at this point it doesn't really matter.
Yes, the result is the same. But the use of XPath
expressions enclosed in {} in an AVT is a basic feature in
XSLT. If Xalan doesn't support them correctly, it is a bug.

But I doubt such a bug can still remain in Xalan today.
Could you please provide an evidence of the problem? As a
minimal transformation and the associate XML input that
reproduce the bug, as well as the symptoms.

Regards,

--drkm


























___________________________________________________________________________
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions !
Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses
http://fr.answers.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--~--

Loading...