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 July 21st, 2010, 05:27 PM
Authorized User
 
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Refer variables from XSLT Include or Import

Is it possible to refer a variable from Include/Import

<xsl:template match="/">
<xsl:for-each select="Data">
<xsl:variable name="Type" select ="Type" />
<xsl:choose>
<xsl:when test="$Type= 'Test1'">
<xsl:variable name="Count">10</variable>
<xsl:variable name="First">First </variable>
</xsl:when></xsl:choose></xsl:for-each>

The above template, i am using as include in the following xslt. Which seems not working. I have conditions based the Type, then the variable list changes, The dynamic variable i am trying to refer to the following xslt to make a generic template

<xsl:for-each select="/ematrix/businessObject">
<xsl:variable name="Type" select="./Type"/>
<xsl:choose>
<xsl:when test="$Type = 'Test1">

<xsl:value-of select="$Count"/>
</xsl:when>
</xsl:choose>
</xsl:for-each>

Error i am getting is Variable $Count has not been declared, $Count is a number, i am trying to loop through that number with other declared variables as a tag name values

Appreciate your help in advance

Last edited by chilly; July 21st, 2010 at 05:29 PM..
 
Old July 26th, 2010, 09:56 AM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

Variables have scope in the template that they've been declared. The $Count Variable has been declared in the <xsl:template match="/"> scope of that particular stylesheet The only place that this variable is accessible from is this particular template. If you try and use this variable in any other template, whether it's included or not, it will not be declared.

If you want to use a variable across included templates, you must declare it as a child of the xsl:stylesheet element. You could also declare it as a parameter and pass it between templates, via an apply-templates/call-templates using xsl:with-param.





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl import/include mapping sammyj727 XSLT 3 July 19th, 2007 04:15 PM
xsl:include / import and tomcat amitda XSLT 2 April 17th, 2007 10:37 AM
call template from diff file? (import vs. include) mister_mister XSLT 5 January 31st, 2007 07:12 PM
Notice: Only variables should be assigned by refer harpua Beginning PHP 0 August 22nd, 2006 10:47 AM
import xslt barsha XSLT 0 September 28th, 2005 03:37 AM





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