XSL Variable problem

Norman Barker

Usenet Archive
Joined
Jun 25, 2004
Messages
5
Reaction score
0
Hi,
I have the following template
<xsl:template match="midas:Request">
<xsl:variable name="var1"
select="string(./midas:DataDescriptorGUID/@GUID)"/>
<test>
<result1><xsl:copy-of
select="$OGC_Type[string(midas:DataDescriptorGUID/@GUID) = @guid]"/></result1> <result2><xsl:copy-of select="$OGC_Type[$var1 = @guid]"/></result2> </test> </xsl:template>

result2 works fine, and I see the XML fragment, yet result1 is empty!

Am I missing a trick, result2 should be the same as result1. Unfortunately in the stylesheet I can't pre-declare the variable since I want to use it in a key.

Thanks

Norman
 

Joris Gillis

Usenet Archive
Joined
Sep 28, 2004
Messages
355
Reaction score
0
I have the following template
<xsl:template match="midas:Request">
<xsl:variable name="var1" select="string(./midas:DataDescriptorGUID/@GUID)"/> <test> <result1><xsl:copy-of select="$OGC_Type[string(midas:DataDescriptorGUID/@GUID) = @guid]"/></result1> <result2><xsl:copy-of select="$OGC_Type[$var1 = @guid]"/></result2> </test> </xsl:template>

result2 works fine, and I see the XML fragment, yet result1 is empty!
Am I missing a trick, result2 should be the same as result1. Unfortunately in the stylesheet I can't pre-declare the variable since I want to use it in a key.

Hi,

interesting question :), you're indeed missing a trick.

in this Xpath expression:
<xsl:variable name="var1" select="string(./midas:DataDescriptorGUID/@GUID)"/> the period (.) selects the context node, which - in this case- is equal to the current node-set of the template (the 'midas:Request' element).

But between the [brackets] in:
<xsl:copy-of select="$OGC_Type[string(midas:DataDescriptorGUID/@GUID) = @guid]"/> , the context node is changed to the node preceding the left bracket ($OGC_Type). So this expression is trying to access the 'midas:DataDescriptorGUID' child nodes of '$OGC_Type', which do not exist. In other words, you cannot access the current node-set with '.' when you're between brackets. You have to use 'current' in stead.

use this:
<xsl:copy-of select="$OGC_Type[string(current/midas:DataDescriptorGUID/@GUID) = @guid]"/>

Hope this helps.

regards,
 

David Carlisle

Usenet Archive
Joined
Jan 5, 2000
Messages
609
Reaction score
0
Norman Barker said:
Hi,
I have the following template
<xsl:template match="midas:Request">
<xsl:variable name="var1"
select="string(./midas:DataDescriptorGUID/@GUID)"/>
<test>
<result1><xsl:copy-of
select="$OGC_Type[string(midas:DataDescriptorGUID/@GUID) = @guid]"/></result1> <result2><xsl:copy-of select="$OGC_Type[$var1 = @guid]"/></result2> </test> </xsl:template>

result2 works fine, and I see the XML fragment, yet result1 is empty!

Am I missing a trick, result2 should be the same as result1. Unfortunately in the stylesheet I can't pre-declare the variable since I want to use it in a key.

Thanks

Norman

your variable var1 is the string value of the
../midas:DataDescriptorGUID/@GUID
evaluated from teh current midas:Request node.
so result2 selcts elements from $OGC_Type whose guid attribute is equal to that.

in $OGC_Type[string(midas:DataDescriptorGUID/@GUID) = ... the midas:DataDescriptorGUID/@GUID is evaluated relative to each element in the $OGC_Type mode set.

so this is probably a different value.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
548,042
Messages
3,104,223
Members
248,131
Latest member
Tonypshaw1

Latest Threads

Top