Developer forum

Forum » Development » XSLT Extension ?

XSLT Extension ?

Sebastian Dammark
Reply

Is it possible to create an XSLT extension so I can get data from a cookie ?


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

You can use a piece of C# code in your xslt (!) to get a cookie – or anything else for that matter:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts">

  <!-- @see http://msdn.microsoft.com/en-us/library/533texsx%28VS.71%29.aspx -->
  <msxsl:script language="C#" implements-prefix="user">
    <msxsl:assembly name="System.Web" />
    <![CDATA[
public string GetCookieValue(string name) {
  var cookie = System.Web.HttpContext.Current.Request.Cookies[name];
  return cookie.Value;
}
    ]]>
  </msxsl:script>

  …

  <xsl:template match="Page">
    <li>
        <xsl:value-of select="user:GetCookieValue('Dynamicweb')" />
    </li>
  </xsl:template>
</xsl:stylesheet>

Best regards,
Mikkel

Votes for this answer: 1
 
Sebastian Dammark
Reply

Thanks alot.  For now this saved my day. :)

 

You must be logged in to post in the forum