Copied to clipboard

Flag this post as spam?

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


  • Alexandru 112 posts 272 karma points
    Oct 08, 2013 @ 12:12
    Alexandru
    0

    Parameter passing to macro

    Hi,

    I am trying to pass a parameter of type text called sourceLink to a macro. This is how I do it:

        <umbraco:Macro sourceLink="http://hsfo.dk/section/artikler/?template=RSS&mime=xml&profile=1196" Alias="BlogNewsFeed" runat="server"></umbraco:Macro>
    

    And in the XSLT I tried both:

    <xsl:variable name="sourceURL" select="/macro/@sourceLink" />
    

    and

    <xsl:param name="source" select="/macro/@sourceLink" />
    

    yet I still get nothing.

    Is there anything I am missing?

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 08, 2013 @ 12:19
    Chriztian Steinmeier
    0

    Hi Alexandru,

    Umbraco creates an XML document that looks like this, for the Macro to use:

    <macro>
       <sourceLink>http://hsfo.dk/section/artikler/?template=RSS&mime=xml&profile=1196</sourceLink>;
    </macro>
    

    - So you can see the attribute from the <umbraco:Macro> tag is converted to an element - so you don't use the @ sign:

    <xsl:variable name="sourceURL" select="/macro/sourceLink" />
    

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 08, 2013 @ 12:21
    Alexandru
    0

    Okay but I get the same error ...

    System.UriFormatException: Invalid URI: The URI is empty.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 08, 2013 @ 12:28
    Chriztian Steinmeier
    0

    Okay,

    • Did you create the parameter for the macro as well? (I still forget that all from time to time :-)
    • It could also be a problem with the query string parameters not being encoded correct...

    Lets get the <macro> output out, to see if it's as expected - put this in your XSLT file:

    <textarea rows="8" cols="40"><xsl:copy-of select="/macro" /></textarea>
    

    Do you get the <sourceLink> element - how does it look?

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 08, 2013 @ 12:33
  • Alexandru 112 posts 272 karma points
    Oct 08, 2013 @ 13:00
    Alexandru
    0

    And yes, I did create the macro for the parameter:

    enter image description here

    Any thoughts?

    I'm using Umbraco 6.1.5

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 10:13
    Alexandru
    0

    bump

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 09, 2013 @ 10:24
    Chriztian Steinmeier
    0

    Hi Alexandru,

    How are you using the $sourceURL variable? Have you checked that it gets the URL correct?

    If you're using GetXmlDocumentByUrl() to fetch its contents, have you checked that you can fetch another URL (i.e., can you fetch another RSS feed successfully?)

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 10:32
    Alexandru
    0

    Hi,

    The problem is when I use the variable inside the GetXmlDocumentByUrl()...

    Yes, I can successfully fetch another RSS feed.

    I did this to see if the parameter is successfully sent:

    <div class="newsContentItem">
        <div class="newsHeadPic">
        <xsl:for-each select="./*[local-name()='thumbnail']">
            <a href="{$articleLink}"><img>
                <xsl:attribute name="src">
                    <xsl:value-of select="@url" />
                </xsl:attribute>
            </img></a>
        </xsl:for-each>
        </div>
        <div class="newsHeadline">
            <span><a href="{$articleLink}"><xsl:value-of select="$sourceURL" /></a></span>
        </div>
      <br/>
    </div>
    

    And it printed the link with no problems.

    However, when I put that in GetXmlDocumentByUrl....it complains

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 10:37
    Alexandru
    0

    I have tried to use it two ways:

    like this:

        <xsl:variable name="rssFeed" select="umbraco.library:GetXmlDocumentByUrl('$sourceURL')"/>
    

    returns this:

    System.UriFormatException: Invalid URI: The format of the URI could not be determined.

    and like this

        <xsl:variable name="rssFeed" select="umbraco.library:GetXmlDocumentByUrl($sourceURL)"/>
    

    returns this:

    System.UriFormatException: Invalid URI: The URI is empty.

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 11:12
    Alexandru
    0

    At the moment, the only solution I have is to pass a number instead, and inside the macro to have 3 big IF statements that check for that number and roll different pieces of code according to each feed source.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 09, 2013 @ 11:20
    Chriztian Steinmeier
    0

    Hi Alexandru - I have a hunch as to what is going on...

    Can you try specifying the URL in the macro parameter using escaped ampersands like this: http://hsfo.dk/section/artikler/?template=RSS&amp;mime=xml&amp;profile=1196

    Note that it uses &amp; instead of a single & - it's required in code, but actually little of a grey area when used like this in a textbox where you just need to paste a URL...

    It may very well be the issue, because of the way the string is handed to the C# extension...

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 11:22
    Alexandru
    0

    I have tried it. It's not that :(

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 09, 2013 @ 11:23
    Chriztian Steinmeier
    0

    Oh - and should probably use the caching version of the GetXmlDocumentByUrl() extension:

    <!-- Cahche the feed for 3 minutes (180 seconds) -->
    <xsl:variable name="rssFeed" select="umbraco.library:GetXmlDocumentByUrl($sourceURL, 180)" />
    

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 09, 2013 @ 11:25
    Chriztian Steinmeier
    0

    Very strange indeed, then... :(

    I'd really like to help you fix this but I'm a little out of ideas now...

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 11:31
    Alexandru
    0

    No problem, It's good that I actually found a way around it.... I hope other people won't have to run into this...

    Thanks for your support!

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 09, 2013 @ 11:39
    Chriztian Steinmeier
    100

    Hi again,

    So I just tried this and something hit me: Where do you get the error? In the backoffice or on the website?

    My test worked right out of the box, but I do of course get that exact "URI is empty" error when saving the XSLT (which is expected because the $sourceURL variable at that point is empty.)

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 11:42
    Alexandru
    0

    Yes, I get the error in the backoffice when I try to save.

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 11:43
    Alexandru
    0

    Should I try and save the XSLT outside of the backoffice?

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 09, 2013 @ 11:44
    Chriztian Steinmeier
    0

    Alright then - then if you click the "Skip errors" checkbox and Save, it should actually work... (?)

    /Chriztian

  • Alexandru 112 posts 272 karma points
    Oct 09, 2013 @ 11:47
    Alexandru
    0

    Hell, it actually does!

    Finally, thank God!

    Cheers man!!!

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 09, 2013 @ 11:51
    Chriztian Steinmeier
    0

    Should I try and save the XSLT outside of the backoffice?

    Yes, you can do that too - I almost always do that, actually.

    Another (and probably better) way of doing it, is to do a check inside the XSLT before calling the extension, because it throws exceptions when something is wrong... perhaps something like this:

    <xsl:variable name="sourceURL" select="/macro/sourceLink" />
    
    <xsl:template match="/">
        <xsl:if test="normalize-space($sourceURL)">
            <xsl:variable name="rssFeed" select="umbraco.library:GetXmlDocumentByUrl($sourceURL, 180)" />
    
            <!-- etc. -->
    
        </xsl:if>
    </xsl:template>
    

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft