Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Replacing a string segment inside a variable? >Thread Next - Re: Replacing a string segment inside a variable? Re: Replacing a string segment inside a variable?To: NULL Date: 7/21/2009 5:39:00 PM
Chris Gannon wrote:
> I've got a variable that's being used as a hyperlink...
> <a href="{@ows_URL}&Source={$PageUrl}">Click This</a>
>
> The link attribute {@ows_URL} has the value "http://mySiteUrl/
> DispForm.aspx?ID=6"
>
> I'd like to change "/DispForm.aspx?" to /EditForm.aspx?"
>
> My guess is that I have to convert @ows_URL to a string first, replace
> the piece I want, and use the a new variable as the link.
>
> Can anyone show me how to do this?
XSLT 2.0:
<a href="{replace(@ows_URL, '/DispForm',
'/EditForm')}&Source={$PageUrl}">Click This</a>
Note that replace takes a regular expression pattern as the second
argument, I think I have choosen a string with '/DispForm' that does not
contain any characters that need to be escaped but be careful if you
want to change the above sample so that you escape anything that needs
to be escaped.
With XSLT 1.0 there is no replace unless you implement it with a named
template that you then need to call inside of an xsl:attribute. On the
other hand for the string you have doing
<a href="{concat(substring-before(@ows_URL, '/'),
'/EditForm.aspx')}&Source={$PageUrl}">Click This</a>
should suffice.
--
Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
