Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

regarding xslt

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28289
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And are those two templates similar in some way to the two templates, with different names, that you posted here?
 
praveen oruganti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
Marshal
Posts: 28289
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28289
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic