CodeGarden 10: The sixth annual Umbraco Developer Conference
June 23-25th 2010 - free ASP.NET MVC pre-conference. Register today!

xslt rendermacrocontent

2/5/2010 4:18:40 AMAvatarshrutiLocation: Chicagoposts: 10Karma: 30

Could anyone give me XSLT example using RenderMacroContent , which renders macro contents added in umbraco rich text edior. I am trying with macro "CWS_Navi" from CWS starter kit as : 

<xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;CWS_Navi&quot; runat=&quot;server&quot; &gt; &lt;/?UMBRACO_MACRO&gt;', $currentPage/@id)" disable-output-escaping="yes"/>

But it is showing me blank string.

Please advice.

Thanks!

2/5/2010 8:20:48 AMAvatarLee KelleherLocation: Yatton, Bristol, UKposts: 445Karma: 1320
Comment with ID: 25461

Hi shruti,

To me, it looks like you are calling RenderMacroContent correctly. It shouldn't make a difference, but try removing the "runat=server" attribute from the macro string.

<xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;CWS_Navi&quot; &gt;&lt;/?UMBRACO_MACRO&gt;', $currentPage/@id)" disable-output-escaping="yes" />

What is the underlying control of the macro? .NET user-control (ASCX) or an XSLT?

If it's a .NET user-control, then it's a no-go!  The rendering of XSLT happens to far into the ASP.NET Page Life-cycle to load-in. (sorry)

Good luck, Lee.

2/5/2010 4:18:19 PMAvatarshrutiLocation: Chicagoposts: 10Karma: 30
Comment with ID: 25527

I tried without server tag and still giving me blank string . This is not a .NET control .

Its an XSLT macro from CWS starter kit , named : [XSLT] Navi . And i am adding this macro to my page using RTE , and want to render its ouput using XSLT.could you provide the XSLT to display any XSLT macro? can pick any XSLT macro from CQS starter site.

Thanks,

2/5/2010 7:41:15 PMAvatarshrutiLocation: Chicagoposts: 10Karma: 30
Comment with ID: 25556

For an example 

Nested macro : 

<?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:umbraco.library="urn:umbraco.library"

exclude-result-prefixes="msxml umbraco.library">

 

 

<xsl:output method="xml" omit-xml-declaration="yes"/>

 

<xsl:param name="currentPage"/>

 

<xsl:template match="/">

 

    <xsl:variable name="rootTextpageNode" select="$currentPage/ancestor-or-self::node [@level = 2 and @nodeTypeAlias = 'CWS_Textpage']" />

 

    <div class="secondaryNav">

        <h3>

            <xsl:value-of select="$rootTextpageNode/@nodeName"/>

        </h3>

 

        <ul>

            <xsl:for-each select="$rootTextpageNode/node">

                <li>

                    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">

                        <xsl:attribute name="class">

                            <xsl:text>selected</xsl:text>

                        </xsl:attribute>

                    </xsl:if>

 

                    <a href="{umbraco.library:NiceUrl(current()/@id)}">

                        <span>

                            <xsl:value-of select="current()/@nodeName"/>

                        </span>

                    </a>

                </li>

            </xsl:for-each>       

        </ul>

    </div>

 

</xsl:template>

 

</xsl:stylesheet>

 

XSLT to read above MACRO

<?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:umbraco.library="urn:umbraco.library"

        exclude-result-prefixes="msxml umbraco.library">

 

 

<xsl:output method="xml" omit-xml-declaration="yes"/>

 

<xsl:param name="currentPage"/>

 

<xsl:template match="/">

 

<xsl:variable name="replaceThis">

        <xsl:text>class="nofollow"</xsl:text>

</xsl:variable>

<xsl:variable name="replaceWith">

        <xsl:text>rel="nofollow"</xsl:text>

</xsl:variable>

<xsl:value-of select="umbraco.library:Replace($currentPage/data[@alias='bodyText'], $replaceThis, $replaceWith)" disable-output-escaping="yes" />

<xsl:value-of select="umbraco.library:RenderMacroContent('&lt;?UMBRACO_MACRO macroAlias=&quot;CWS_SubNavi&quot; runat=&quot;server&quot; &gt; &lt;/?UMBRACO_MACRO&gt;', $currentPage/@id)" disable-output-escaping="yes" />

</xsl:template>

</xsl:stylesheet>

 

And this shows the contents of the page but not rendering macro . 

 

Please advice 

 

2/5/2010 8:11:02 PMAvatarKim AndersenLocation: 8260 Viby J, Denmarkposts: 202Karma: 438
Comment with ID: 25557

Hi Shruti

I have used the following code to render my content from a richtext editor:

<xsl:variable name="content" select="$currentPage/data[@alias='content']"/>
<xsl:value-of select="umbraco.library:RenderMacroContent($content, $currentPage/@id)" disable-output-escaping="yes"/>

I used this to successfully render my content including a macro inserted into the richtext editor. Hope this helps out.

 

/Kim A

2/9/2010 1:38:49 PMAvatarChrisLocation: Brussels, Belgiumposts: 45Karma: 48
Comment with ID: 25792

Great snippet Kim! This is exactly what i was looking for! :)

2/10/2010 4:16:10 AMAvatarshrutiLocation: Chicagoposts: 10Karma: 30
Comment with ID: 25861

Kim,

That snippet worked good, i am able to displa macros , but i guess for .NET controls it does not work . As i am able to display .NET controls but not able to do postback.

But thank you so much for your help. :)

Please login or Sign up To post replies