473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

XSL Variable problem

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

--
Take the DOG out to reply
Jul 20 '05 #1
2 1698
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,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
Norman Barker <no*****@DOGcomsine.co.uk> writes:
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

--
Take the DOG out to reply


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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nick Whitelegg | last post by:
Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication script which checks a username/password. If the...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
7
by: ben | last post by:
hello, an algorithm book i'm reading talks about the connectivity problem/algorithm. it gives a number of examples where the connectivity problem applies to real life situations (like, the...
9
by: Pyenos | last post by:
Approach 1: class Class1: class Class2: def __init__(self):self.variable="variable" class Class3: def method():print Class1().Class2().variable #problem Approach 1.1:
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
10
by: Mason Barge | last post by:
I have a standard POST form consisting of two types of input: text input and textarea. The form downloads current settings from a mysql database. The user can update the information by modifying...
1
NeoPa
by: NeoPa | last post by:
Problem Description : In VBA there is an option to enforce declaration of variables in your code. With this set, any reference to a variable that has not been previously declared (Dim; Private;...
20
by: teddysnips | last post by:
Weird. I have taken over responsibility for a legacy application, Access 2k3, split FE/BE. The client has reported a problem and I'm investigating. I didn't write the application. The...
3
Atli
by: Atli | last post by:
Hi everybody. This is not so much a problem, since I have already managed to find a solution, but my solution requires the use of the eval() function, which I just hate to use. The problem is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.