• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Is it Possible in XSL

 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
Is it possible in xsl that in a stylesheet declare a variable
and assign it some value and then use its value anywhere .THe
value may be a string URL.
Awais Bajwa
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you to achieve through this.
Elaborate more. Where do you want to use this variable?
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
you can use. there won't be problem.
------------------
glkishore,
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ofcourse ,u can use xsl:variable tag, but one disadvantage (ok for xsl) u can't hv dynamic values for that or it's constant ,u can't change values dynamically, even this one has local and global access,
so it's all depends on where u use this one,
 
Awais Bajwa
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi ,
Thanks a lot ...
But if it is possible from xsl:variable tag then ,can we get the value for that variable from an xml file .
Regards Awais Bajwa.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
<xsl:variable name="myVar" select="document('myXML.xml')/root/someElement..."/>
 
Awais Bajwa
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sir ,
I am trying this code (In XML Spy).but error is
"<xsl:variable> is not allowed to use here".
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:variable name="myVar" select="document('myXML.xml')/root/someElement..."/>

<xsl:template match= "/">
<html>

<body bgcolor="cyan">
<h2 align="center"><xsl:apply-templates select="//CHAPTITLE"/></h2>
<table border="1" style="background-color:#99cc99;
color:#000000;
;;;
;;;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Also tell me that if I just need a variable to store some string
and later to use that variable in anyplace in the XSl File .
I tried it like this
<xsl:variable name="n">2</xsl:variable>
but I dont know to call it.
Give a code view plz.
As I am a bit new to xsl.
Regards .
Bajwa
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Awais,
As far as your later part of your above mentioned querry goes,you can assign a variable say 'var1' as under:
<xsl:variable name="var1" select="/Organisation/whatever/whatever2..">
:
:
To use the value in the code you write:
<xsl:value-of select="$var1"/>
Hope this helps,
Regards,
Milan Doshi
 
Awais Bajwa
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mapraputa and doshi,
This simple thing is seem to be very complex.
Plz tell me why I am getting error in this code..(Complete )

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match= "/">
<html>
<body>
<xsl:variable name="var1" select="/Organisation/whatever/whatever2.."/>
<center><xsl:value-of select="$var1"/></center>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
regards bajwa
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plz tell me why I am getting error in this code
Because your namespace http://www.w3.org/TR/WD-xsl points to outdated version of MSXML processor, which did not support variables. I run your example and got the message "Keyword xsl:variable may not be used in namespace http://www.w3.org/TR/WD-xsl." Use
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
instead.
Also "/Organisation/whatever/whatever2.." was given as an example, your XML probably doesn't have such elements, not to mention ".." rhetorical fugure
You can place
<xsl:variable name="var1" select="2"/>
<center><xsl:value-of select="$var1"/></center>

inside your <body> tag. Then you can see expected output:
<html>
<body>
<center>2</center>
</body>
</html>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!