| Author |
regarding xslt
|
praveen oruganti
Ranch Hand
Joined: Feb 05, 2007
Posts: 73
|
|
I have a doubt in xslt: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:variable name="x"> <xsl:call-template name="blob"> <xsl:with-param name="par" select="."/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$x"/> </xsl:template> <xsl:template name="blob"> <xsl:variable name="name"> <xsl:element name="op"> <xsl:value-of select="2"/> </xsl:element> </xsl:variable> <xsl:param name="par" > <xsl:value-of select="$name"/> </xsl:param> </xsl:template> </xsl:stylesheet> I have two templates in which i have to use a variable in template1 which is used in template2. can anyone solve this problem.
|
Regards,<br />Praveen Oruganti<br />Software Programmer
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
And are those two templates similar in some way to the two templates, with different names, that you posted here?
|
 |
praveen oruganti
Ranch Hand
Joined: Feb 05, 2007
Posts: 73
|
|
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:variable name="x"> <xsl:call-template name="blob"> <xsl:with-param name="par" select="."/> </xsl:call-template> </xsl:variable> <xsl:value-of select="$x"/> </xsl:template> <xsl:template name="blob"> <xsl:variable name="name"> <xsl:element name="op"> <xsl:value-of select="2"/> </xsl:element> </xsl:variable> <xsl:param name="par" > <xsl:value-of select="$name"/> </xsl:param> </xsl:template> </xsl:stylesheet> How can i retrieve the param value par from blob template which must be used in the root node template
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
You can't. It's local to the template where it's declared. How about if you tell us your real requirement instead of asking how to do impossible things in fake code? Probably it will turn out you never needed to do that in the first place.
|
 |
praveen oruganti
Ranch Hand
Joined: Feb 05, 2007
Posts: 73
|
|
Thanks paul. basically according to my requirement i have to use a variable from one template into other template. but you have told that it is impossible. if i put that variable as global then i think, i can access it.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Well, sure you can access the variable in your main template if you declare it there. But then you won't be able to modify it in the "blob" template. You don't seriously have "Use a variable in one template that's declared in a different template" in your business requirements, do you? I would expect that was more like how you decided to implement the business requirement. That's why I tried to find out what the business requirement was, that you decided to implement in this way.
|
 |
praveen oruganti
Ranch Hand
Joined: Feb 05, 2007
Posts: 73
|
|
according to business requirement, There are two xsl's. First xsl: <xsl:template match="op"> <xsl:element name="bus"> <xsl:value-of select="$bus"/> </xsl:element> </xsl:template> Second Xsl: <xsl:template match="blob"> <xsl:value-of select="$somevariable"> </xsl:template> Main requirement i should create a variable containing the value $bus in first xsl and then i should use that variable in second xsl. can you please resolve this issue. [ May 17, 2007: Message edited by: praveen oruganti ]
|
 |
 |
|
|
subject: regarding xslt
|
|
|