Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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
  #1 (permalink)  
Old December 4th, 2007, 09: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

  #2 (permalink)  
Old December 5th, 2007, 05: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)
  #3 (permalink)  
Old December 5th, 2007, 05:18 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
  #4 (permalink)  
Old December 5th, 2007, 11: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 ?
  #5 (permalink)  
Old December 5th, 2007, 12:03 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
  #6 (permalink)  
Old December 5th, 2007, 12:07 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
  #7 (permalink)  
Old December 5th, 2007, 12:16 PM
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.



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 02:07 PM
global variable? milk_vanilla Classic ASP Basics 3 January 8th, 2005 06:50 PM
global variable in c# kobystud C# 3 April 22nd, 2004 05:56 AM





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