Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 4th, 2007, 08:18 PM
Authorized User
 
Join Date: Dec 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default comapring global variable value to local variable

Can someone pl post an example for an xsl where the following happens in a sequence

1.global variable is declared
2.some part later in the code this global variable is assigned a value
3.another variable - a local variable that has a value is compared using
4.xsl if test $local = $global

Reply With Quote
  #2 (permalink)  
Old December 5th, 2007, 04:04 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

No, no-one can, for the simple reason that in XSLT you cannot assign a variable other than at the point of declaration.
The only possible way would be an extension function but that would not be a pure XSLT solution.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old December 5th, 2007, 04:18 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 Posts
Default

Please explain the problem you are trying to solve (what are the inputs and desired outputs) and perhaps we can then tell you how to approach a solution the XSLT way. The way you are describing is too low-level and procedural for use with a declarative language like XSLT.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old December 5th, 2007, 10:58 AM
Authorized User
 
Join Date: Feb 2007
Location: , , USA.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I am also encountering similar situation but there is no straight forward approch to declare variable as global and assigned it value in later part. I have situation ... I have declared rules in XSLT(my custome rules template based for application not xslt specific), Now in 'Rule 1' i am calling server( csharp object) to get values. I want to store this value so in subsequent rules i can use it. In next rule i have to pass these values as input parameter to csharp function to get more specific value.(rather than calling server again for those values) situation like these  should be handled by global variable which seems little tricky here in xslt which i am trying to figuring out...Here code for Rule from which i am getting value firsr time...
-------

<xsl:template name="categoryOpportunity">
  <rule>
      <xsl:variable name="RecommendedNodeSet" select="jasper:GetCategoryOpportunity(3)" /> <message>

        <xsl:if test="$currScope = 'overall'">
Overall, your areas of greatest opportunity, in order of priority, are:
        </xsl:if>
        <xsl:call-template name="displayFragment">
            <xsl:with-param name="fragmentName">categoryOpportunity</xsl:with-param>
        </xsl:call-template>
    </message>
        <data>

              <xsl:if test="$currScope = 'overall'">
                <xsl:for-each select="$RecommendedNodeSet//Category">
                    <xsl:value-of select="$RecommendedNodeSet//Category"></xsl:value-of>
                </xsl:for-each>
            </xsl:if>
            <xsl:if test="$currScope != 'overall'">
We recommended you first review your areas of greatest opportunity Overall.If you wish to focus entirely on <xsl:value-of select="$currScope"></xsl:value-of>
            <xsl:call-template name="displayFragment">
                   <xsl:with-param name="fragmentName">categoryOpportunity</xsl:with-param>
            </xsl:call-template>
                <xsl:value-of select="$RecommendedNodeSet"></xsl:value-of>
            </xsl:if>
        </data>
    </rule>
</xsl:template>

------------

Variable "RecommendedNodeSet" i want to access later in other rules...how do i assign it as gloabl ?
Reply With Quote
  #5 (permalink)  
Old December 5th, 2007, 11:03 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 Posts
Default

>in subsequent rules

Anything that talks about the behaviour of an XSLT stylesheet and uses temporal words like "before", "after", "subsequent", or "later" is on dangerous territory. Thinking about XSLT processing as a temporal sequence of actions is simply the wrong model, and gets you into all kinds of knots. You have to learn to think declaratively.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #6 (permalink)  
Old December 5th, 2007, 11:07 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 Posts
Default

>Variable "RecommendedNodeSet" i want to access later in other rules

Of course if jasper:GetCategoryOpportunity() is a pure function then you can just move

<xsl:variable name="RecommendedNodeSet" select="jasper:GetCategoryOpportunity(3)" />

outside the template and it becomes a global variable automatically.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old December 5th, 2007, 11:16 AM
Authorized User
 
Join Date: Feb 2007
Location: , , USA.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Default

yes that the best way...But like other languages seems we can't declare first and assign value later here..Thanks michael.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to declare the global variable in global.asax? calyn_gately ASP.NET 3.5 Basics 0 August 6th, 2008 08:06 PM
Global Variable techfreak123 XSLT 0 August 3rd, 2006 07:45 AM
global variable melvik C# 37 March 2nd, 2005 01:07 PM
global variable? milk_vanilla Classic ASP Basics 3 January 8th, 2005 05:50 PM
global variable in c# kobystud C# 3 April 22nd, 2004 05:56 AM



All times are GMT -4. The time now is 03:42 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.