Copied to clipboard

Flag this post as spam?

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


  • maanehunden 61 posts 105 karma points
    Jul 01, 2010 @ 15:14
    maanehunden
    0

    How to make a XSLT macro that can be used inside a richtext editor

    Hi 

    I've been trying to make a XSLT macro which can be used inside a richtext editor, and i just can't get it to work. 

    this is what i've done so fare. 

    I started out with making a XSLT and macro, and added a "imageUrl" property to the macro under parameters tab, 

    her's my xslt 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: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" xmlns:tagsLib="urn:tagsLib" 
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    
    <xsl:variable name="imageUrl" select="/macro/imageUrl"/>
    
      <xsl:template match="/">
       <xsl:value-of select="$currentPage/@id"/>
       <xsl:value-of select="$imageUrl"/>
      </xsl:template>
    </xsl:stylesheet>
    

     

    but when i add this macro in my richtext editor and publish,.. nothing,.. nothing gets rendered,.. 

    what am I missing.. ?



  • Ruslan 12 posts 32 karma points
    Jul 01, 2010 @ 17:09
    Ruslan
    0

    Hi,

    I noticed that your XSLT template doesn't contain any HTML markup.  

    Please add some html to your template

    <?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" 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" xmlns:tagsLib="urn:tagsLib"
            exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>

    <xsl:variable name="imageUrl" select="/macro/imageUrl"/>

     
    <xsl:template match="/">
       
    <xsl:value-of select="$currentPage/@id"/>
       
    <xsl:value-of select="$imageUrl"/>
        <strong>Hello world!</strong>
     
    </xsl:template>
    </xsl:stylesheet>
    2) if you want to see visualized content of macros in rich text editor you should set Render content in editor to True on Macro Properties Tab

    Rgds, Ruslan

  • maanehunden 61 posts 105 karma points
    Jul 01, 2010 @ 17:47
    maanehunden
    0

    Hey Ruslan 

    thanks for the reply,.. i was hoping to see the value of my "imageUrl" variable non the less the currentPageID (which is always there), rendered in my browser,.. 
    but it's like the XSLT macro is never run,.. I've tryed to put HTML in it as you have proposed nothing happend )c:

    I am using another XSLT to display content of this Richtext editor,.. but when i display the whole node i can see following markup displayed in my browser,..

    <?UMBRACO_MACRO imageurl="image goes here" macroAlias="ImageByUrl" />, but no macro,..

      Does anybody know why it is so..

  • Ruslan 12 posts 32 karma points
    Jul 01, 2010 @ 19:16
    Ruslan
    0

    Hi,

    Just copied xslt code snippet provided by you to my umbraco installation and all works as expected.

    I think you should restart your umbraco installation and recreate your macros

    // i was hoping to see the value of my "imageUrl" variable

    Do not forgot add corresponding parameter "imageUrl" to your macros

    Rgds,Ruslan 

  • maanehunden 61 posts 105 karma points
    Jul 01, 2010 @ 19:57
    maanehunden
    0

    Hi Ruslan

    Thanks again,.. I've finally figured what the problem is,. (c:

    when i call my "bodyText" page field(which stores data data from richtext editor) with XSLT, for some unknown reason macroes(which were embedded with richtext editor) never get rendered,.. this must be a bug of some sorts !!,.. 

    XSLT: <xsl:value-of select="umbraco.library:RemoveFirstParagraphTag(./data[@alias = 'bodyText'])" />

    when i call my "bodyText" page field with .Net it works and all is rendered correctly,.. 

    .Net: <umbraco:Item field="bodyText" runat="server"></umbraco:Item>

    It just sounds wired to me,..I've tried different approaches to make it work but failed )c:,  Is there a way to make macroes work with richtext editor, if they are processed with XSLT instead of .NET.   ?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 01, 2010 @ 20:42
    Kim Andersen
    1

    Hi there Maanehunden

    Maybe you can try out the RenderMacroContent-extension like this:

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

    The problem occours because you are trying to render a XSLT-macro through another XSLT-macro. But the above code should work if you are trying to render the macro on the current page ($content, $currentPage/@id).

    /Kim A

  • maanehunden 61 posts 105 karma points
    Jul 01, 2010 @ 21:57
    maanehunden
    0

    Howdy Kim,.

    Thanx that is just Awesome,.. that is it,.. that did the trick,..  

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jul 01, 2010 @ 22:20
    Kim Andersen
    0

    Glad it worked out for you.

    Another approach is to use the undocumented Item-extension like this:

    <xsl:value-of select="umbraco.library:Item($currentPage/@id,'bodytext')" />

    I didn't think of that when I wrote my first answer. It's less code, and actually the Item-extension makes sure that you can edit the content i canvas-mode as well. That option is normally not possible when rendering the content through XSLT :)

    /Kim A

  • Doug Moore 48 posts 103 karma points c-trib
    Nov 17, 2015 @ 20:00
    Doug Moore
    0

    I have run into the problem using this approach (umbraco.library:Item). On occasion the macro shows content that is saved, but not published.

    I can get around this by using RenderMacroContent, but in some instances the XSL macro is attempting to render a .Net Macro which does not work in RenderMacrContent, but does work in Item.

  • maanehunden 61 posts 105 karma points
    Jul 01, 2010 @ 23:36
    maanehunden
    0

    It worked like a charm to,.. (c: thnx for sharing.

    /maanehunden

Please Sign in or register to post replies

Write your reply to:

Draft