liquide
liquide

Reputation: 1383

XSL: how to put substring to xsl:attribute - part of url adress

I code custom search result page on Sharepoint. I've got a problem with XSLT.

Search result from SP is something like:

<Result>
...
<url>http://server/_bdc/name/source.aspx?id=444</url>
...
</Result>

But I want to make own link, from this url variable I want to cut only the id (444):

<a href="http://mynewlink/page.aspx?id=444">MyResult</a>

I tried something like (based on standard SP template)

...
<a>
<xsl:attribute name="href">        
{concat('http://mynewlink/page.aspx?id=', substring-after("{url}", "="))}
</xsl:attribute>
</a>
...

but it didn't work - I don't know where put this concat...

Upvotes: 1

Views: 828

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243599

Your code is "almost" correct, start by replacing:

"{url}" 

with:

url

Here is a complete transformation:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="/*">
    <a href=
       "http://mynewlink/page.aspx?id={substring-after(url,'=')}">MyResult</a>
 </xsl:template>
</xsl:stylesheet>

When this is applied on the provided XML document:

<Result>
 ...
 <url>http://server/_bdc/name/source.aspx?id=444</url>
 ...
</Result>

the wanted, correct result is produced:

<a href="http://mynewlink/page.aspx?id=444">MyResult</a>

Upvotes: 3

Related Questions