Problems with C# in XSLT Options
roffers
Posted: Wednesday, September 26, 2007 4:01:58 PM
Rank: Newbie

Joined: 9/26/2007
Posts: 7
Okay I have the following code, but I can't seem to get it working at all. I know it's failing at the Request.UrlReferrer.ToString() line. But can anyone tell me why? Or more importantly how to fix it.

Many thanks in advance.


Code:

<?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:msxsl="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:mycustomprefix="urn:mycustomprefix"
    exclude-result-prefixes="msxml umbraco.library mycustomprefix msxsl">
    <xsl:output method="xml" omit-xml-declaration="yes" />
    <msxsl:script language="CSharp" implements-prefix="mycustomprefix">
     
            public string GetUrl()
            {
                [b]return Request.UrlReferrer.ToString();[/b]
            }
         
    </msxsl:script>
    <xsl:param name="currentPage" />
    <xsl:variable name="MyTestVariable" select="mycustomprefix:GetUrl()" />
    <xsl:template match="/">
        <xsl:value-of select="$MyTestVariable" />
    </xsl:template>
</xsl:stylesheet>

uncas
Posted: Monday, October 08, 2007 10:43:03 PM
Rank: Enthusiast

Joined: 8/21/2007
Posts: 13
I'm not too experienced in writing C# inside XSLT, but I assume it's the <strong> tags that are messing with you. You can't have HTML tags inside a C# method like that. Try and change the method to return:

return String.Format( "<strong>{0}</strong>", Request.UrlReferer.ToString() );

I don't really mean what I just said...
uncas
Posted: Monday, October 08, 2007 10:52:58 PM
Rank: Enthusiast

Joined: 8/21/2007
Posts: 13
Perhaps it's even better to completely forget the <strong> tag in the c# method, and use it like this:

Code:

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE xsl:Stylesheet [ 
<!ENTITY nbsp " "> 
]> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" 
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:mycustomprefix="urn:mycustomprefix" 
exclude-result-prefixes="msxml umbraco.library mycustomprefix msxsl"> 
    <xsl:output method="xml" omit-xml-declaration="yes" /> 
    <msxsl:script language="CSharp" implements-prefix="mycustomprefix">

        public string GetUrl() 
        { 
            return Request.UrlReferrer.ToString();
        }

    </msxsl:script> 


    <xsl<img src='/include/emotions/tongue.gif'/>aram name="currentPage" /> 
    <xsl:variable name="MyTestVariable" select="mycustomprefix:GetUrl()" /> 

    <xsl:template match="/">
        <strong><xsl:value-of select="$MyTestVariable" /></strong>
    </xsl:template>
</xsl:stylesheet>


I don't really mean what I just said...
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.