• 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

creating links in XSL

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am presenting my XML data in tabular format using XSL Transformation in my servlets
Now one column in table presentation contains links for more details to another servlet
which i am doing in xsl like this
<td><font face="Verdana"><u><font color="#3333FF">
<a href="./IPSPSumm?id={$ID}&name={$NAME}&">
<xsl:value-of select="FULLNAME"/>
</a></font></u>
if for example xsl:variable {$ID} is 2001 and {$NAME} is 'SMITH, DON'
which convert it into following html
<td><font face="Verdana"><u><font color="#3333FF">
<a href="./IPSPSumm?id=2001&name=SMITH, DON&">
<xsl:value-of select="FULLNAME"/>
</a></font></u>
because {$NAME} can contain white spaces entire name value is not transferred to servlet.
how can i convert {$NAME} value into url format(like SMITH,%20DON) so that i can get html like this.
<td><font face="Verdana"><u><font color="#3333FF">
<a href="./IPSPSumm?id=2001&name=SMITH,%20DON&">
<xsl:value-of select="FULLNAME"/>
</a></font></u>
is it possibe to this in xsl??
please help
thanks
kripal
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a translate function in XSL may be you know about that, which will translate string in this manner. I havn't yet tried it.....
e.g., translate($name,' ','%20')
[This message has been edited by Tanya Rawat (edited August 15, 2001).]
 
Kripal Singh
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
won't work because this is how translate works
The following function call returns "BAr":
translate("bar","abc","ABC")
If there is a character in the second argument string with no character at a corresponding position in the third argument string (because the second argument string is longer than the third argument string), occurrences of that character in the first argument string are removed.
The following function call returns "AAA":
translate("--aaa--","abc-","ABC")
If a character occurs more than once in the second argument string, the first occurrence determines the replacement character. If the third argument string is longer than the second argument string, excess characters are ignored.
If an argument is not of type string, it is first converted to a string and then evaluated.
in my case third argument "%20" is larger than second " " so excess chars are ignored.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob DuCharme's "XSLT Quickly" chapter 5.7.2. "Search and replace" provides with GlobalReplace template. You can download it from http://www.manning.com/ducharme/source.html file name: xq332.xsl And I am still waiting for my percent from Bob DuCharme
 
Tanya Rawat
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is interesting.....
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... but too long. 36 lines for one simple replacement function! Here is slightly less verbose variant: http://www.dpawson.co.uk/xsl/sect2/replace.html
but still verbose. I wonder if there are any extension functions, so we can code something like
xalan:replace ($myString, ' ', '%20')
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... except that in your particular case everything is much simplier. Just include
<xsl:output method="html"/>
and all blanks in URLs will be converted to "%20" automatically.
I tried this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:variable name="test">SMITH DON</xsl:variable>
<xsl:template match="/">
<a href="{$test}">...</a>
</xsl:template>
</xsl:stylesheet>

and here is the output:
<a href="SMITH%20DON">...</a>
[This message has been edited by Mapraputa Is (edited August 15, 2001).]
 
Tanya Rawat
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great !! it worked....
 
Kripal Singh
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
work fine with IE some problem with Netsacpe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!