0

I have the following in my XSLT:

<a>
        <xsl:attribute name="href">
          <xsl:value-of select="concat($DownloadPath,FilePath)" />
        </xsl:attribute>
        <xsl:attribute name="target">_blank</xsl:attribute>
        <img src="Content/Images/download.jpg" style="border-width:0px;">
          <xsl:attribute name="title">
            <xsl:value-of select="FilePath" />
          </xsl:attribute>
        </img>
      </a>

On my homecontroller I have an action GetFile(string file) which should return the file when the Href is clicked.

How can I achieve this? I have been looking at different solutions already but nothing seems to work.

Bart Schelkens
  • 1,235
  • 4
  • 21
  • 45
  • Is that an XSLT question? If your XSLT generates HTML with a link to a URI and that URI points to some controller implemented in ASP.NET code then I don't see why that question is XSLT related; it is not clear what code you have on the server and what you expect to happen on the client. What does "should return the file mean", should the browser just download the file linked to and offer the browser user to save it? – Martin Honnen May 06 '21 at 09:09
  • @MartinHonnen Sorry my question is not that clear. The xslt together with the xml create and html-page which is displayed to the user. In that page the user can click a link to download a file. However I only have a physical path the file (i.e. c:\temp\file.pdf) so I need to call an action on my controller to get the file and return that to the user – Bart Schelkens May 06 '21 at 09:14
  • Perhaps first add tags and explanation to your question as to which ASP.NET framework (MVC, which version, .NET framework or Core) you use. Or try existing answers like https://stackoverflow.com/questions/730699/how-can-i-present-a-file-for-download-from-an-mvc-controller – Martin Honnen May 06 '21 at 09:57
  • I think this is an HTML question. When you know what HTML will achieve the desired runtime behaviour, generating that HTML using XSLT should be straightforward. Your problem is that you don't know what HTML you want your stylesheet to output. – Michael Kay May 06 '21 at 11:09
  • What I want my XLST to produce is the following: "> – Bart Schelkens May 07 '21 at 06:06
  • Where do you run the XSLT, on the client or on the server? The syntax of your code in the comment `<%: Url.Action("GetFile", "Home", new { path= d:\data\download\myfile.doc" }) %>` seems to be server-side ASP or Razor code. – Martin Honnen May 07 '21 at 18:00

2 Answers2

0

I would make your controller responsible for returning the file when a link without $DownloadPath is clicked. In that way you stay in controle. So the href is a call to your controller with just enough info that your controller is able to resolve that file to return as Download.

Siebe Jongebloed
  • 3,906
  • 2
  • 14
  • 19
0

I found the answer by searching and trying. I wrote in my XSLT the following:

<xsl:attribute name="href">
    <xsl:value-of select="$UserLanguageLower" />\Home\GetFile?fileName=<xsl:value-of select="FilePath"/>
</xsl:attribute>

This does the trick.

Bart Schelkens
  • 1,235
  • 4
  • 21
  • 45