Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2011, 03:04 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Arrow Two ways to set a variable to a temp result, why does one work and the other not?

I am using Saxon 9 EE with Oxygen XML 12.1

I an trying to set a variable to a temporary result and I have a way that works, and a way that does not. When I dump the results, they look the same to me. I cannot figure out why one works and the other doesn't.

This way works:
Code:
<xsl:variable name="iterdef"
            select="nmirepo:findIteratorDef($myData/IteratorTagRef[1]/@Idref)"/>
This way does not:
Code:
<xsl:variable name="iterdefx">
   <xsl:sequence select="nmirepo:findIteratorDef($myData/IteratorTagRef[1]/@Idref)"></xsl:sequence>
</xsl:variable>
When I dump using:
Code:
<xsl:message>
   [iterdef]
   <xsl:sequence select="$iterdef"></xsl:sequence>
   [iterdefx]
   <xsl:sequence select="$iterdefx"></xsl:sequence>
   [-----]
</xsl:message>
I get:

Code:
                        [iterdef]
                        <IteratorDef xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><IteratorTag Id="BABEGAJE">allOCn</Iterat
orTag><IteratorList><IteratorChoice>3</IteratorChoice><IteratorChoice>12</IteratorChoice><IteratorChoice>48</IteratorChoice><Iterato
rChoice>192</IteratorChoice></IteratorList></IteratorDef>
                        [iterdefx]
                        <IteratorDef xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><IteratorTag Id="BABEGAJE">allOCn</Iterat
orTag><IteratorList><IteratorChoice>3</IteratorChoice><IteratorChoice>12</IteratorChoice><IteratorChoice>48</IteratorChoice><Iterato
rChoice>192</IteratorChoice></IteratorList></IteratorDef>
                        [-----]
Which looks identical to me (do you see any differences?)

I have not included the findIteratorDef() code, it basically dereferences the Idref tag and returns what it finds as the temporary result that you see in the output.

If I pass on the $iterdef content to the rest of my code it works the way I expected it to. If I pass $iterdefx content, it does not. It basically acts as though I passed nothing at all.

My question is, are the two ways I'm setting the variables equivalent?
(I'm guessing not since I do not get equivalent results)
So, besides what I see visually by using xsl:message to dump to my display, what else can be different with the two version of the variables that is unseen?
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare

Last edited by mphare; March 4th, 2011 at 03:06 PM..
 
Old March 4th, 2011, 07:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When you use the select attribute of xsl:variable, the variable contains references to the original nodes. When you use a contained child element (and no "as" attribute on the xsl:variable) a new temporary tree is created containing a copy of the selected nodes. The copy looks the same if serialized, but the variable doesn't contain the original nodes. The most obvious way of seeing the difference is by navigating upwards from the selected node: in the first case $var/ancestor::* will select all the ancestor elements in the node's original tree; in the second case $var/ancestor::* will find nothing, because the copied node has no ancestors.

You'll find all this explained in great detail in the xsl:variable section of my book.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
mphare (March 5th, 2011)
 
Old March 5th, 2011, 12:27 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Thanks, Michael. I'll take a look at the xsl:variable section a little closer.
I'm still coming to terms regarding the difference between xsl:copy-of and xsl:sequence.. I thought using xsl:sequence solved the problem you are describing. But I will read the section in more detail.

Thanks again, and have a nice weekend!
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Temp Table Variable in Stored Procedure rweide SQL Server ASP 2 April 15th, 2011 03:50 PM
result set rajesh_css SQL Language 2 May 18th, 2009 03:33 PM
Variable or parameter twice within the same temp Navy1991_1 XSLT 4 June 9th, 2008 02:29 PM
How to set a single location of java plug in temp orfano Pro Java 0 September 27th, 2006 10:06 AM
How to Swap two integers without temp variable ramk_1978 C# 2 February 28th, 2006 08:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.