Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dandrayne 1138 posts 2262 karma points
    Sep 22, 2009 @ 10:58
    dandrayne
    1

    Also possible using inline script in xslt

    The below script replicates the functionality in only xslt, allowing for passing the function a filename and mime type from directly within the xsl (thanks doug for the informative blog post).  As noted in the comments however, there may be reasons for using the compiled usercontrol.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:gecko="urn:gecko-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets gecko">
    <xsl:output method="text" omit-xml-declaration="yes"/>


    <msxml:script language="CSharp" implements-prefix="gecko">
    <msxml:assembly name="System.Web" />
    <msxml:using namespace="System.Web" />

    <![CDATA[
    public void changeOutPut(String ContentType, String FileName) {
    HttpContext.Current.Response.ContentType = ContentType;
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + FileName);
    }
    ]]>

    </msxml:script>


    <xsl:param name="currentPage"/>
    <xsl:template match="/">
    <xsl:value-of select="gecko:changeOutPut('text/csv','xslttest.csv')" />
    </xsl:template>

    </xsl:stylesheet>

    Dan

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Sep 22, 2009 @ 11:45
    Warren Buckley
    0

    Dan,
    Can you tell me why you have done this instead of using the

    umbraco.library:ChangeContentType('text/xml')

    I may be missing something that your package/control does that the umbraco.library version doesnt.

    Warren :)

  • Petr Snobelt 923 posts 1535 karma points
    Sep 22, 2009 @ 12:21
    Petr Snobelt
    0

    @Warren: content-disposition which set downloaded file name, which display to user in save dialog.

  • dandrayne 1138 posts 2262 karma points
    Sep 22, 2009 @ 12:34
    dandrayne
    0

    Indeed, it's the download filename that can't be set using the built-in control (afaik), and it seemed sensible to just have one function that allowed setting the MIME type and the filename in one go.

  • Warren Buckley 2106 posts 4836 karma points MVP ∞ admin hq c-trib
    Sep 22, 2009 @ 13:14
    Warren Buckley
    0

    OK this makes sense now :)

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Sep 22, 2009 @ 17:06
    Douglas Robar
    2

    I've found a solution to the temporary files issue. It is noted in the comments to my blog post (http://blog.percipientstudios.com/2009/9/21/advanced-xslt-with-net-namespaces.aspx) but the short answer is:

    Set the umbracoDebugMode to false in the web.config and temporary files aren't created.

     

    Now you have two choices... inline XSLT, or a compiled package. Use whichever you prefer. Isn't umbraco's flexibility wonderful?!?

    cheers,
    doug.

  • dandrayne 1138 posts 2262 karma points
    Sep 22, 2009 @ 17:43
    dandrayne
    0

    Cheers Doug, your blog post couldn;t have come at a more appropriate time!

    Dan

Please Sign in or register to post replies

Write your reply to:

Draft