Copied to clipboard

Flag this post as spam?

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


  • Simon Dingley 1474 posts 3431 karma points c-trib
    Nov 20, 2010 @ 13:28
    Simon Dingley
    0

    XPath Macro Parameter

    Not sure if this is possible or not but I have a macro and for one of the parameters I would like to provide an XPath query that walks up the tree finding the closest node with a specific document property if the current node does not have one, and then pass that document property in as the parameter.

    As an example:

    <umbraco:macro runat="server" Alias="MyMacro" MyParam="string($currentPage/ancestor-or-self::* [@isDoc] /docProperty) != ''" /> 

     

  • Richard Soeteman 4045 posts 12898 karma points MVP 2x
    Nov 22, 2010 @ 10:40
    Richard Soeteman
    0

    Hi Simon,

    You can use recursive Macro Properties for this. Normally you pass a parameter using [#documentProperty].This will only look in the current document. When you want to do a recursive lookup of the value, you can use [$documentProperty].

    This WIKI explains the parameter syntax in detail.

    Cheers,

    Richard

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Nov 22, 2010 @ 10:44
    Simon Dingley
    0

    That's great Ricahrd thanks, it solved my problem. It is also worth mentioning that it was your "Meta tags, Umbraco:item control and runat="server" magic" blog post that led me to the solution.

     

  • David Cardine 7 posts 27 karma points
    Feb 17, 2011 @ 16:59
    David Cardine
    0

    I'm looking at trying to do something similiar and I'm not having success.

    i originally had my xpath query hardcoded in my xslt file and I'm extracting it in order to pass it through my macro. here's what i have.

    <umbraco:Macro Alias="PostListMacro"  runat="server" sourcePath="[$currentPage/Posts/Year/Month/*]"></umbraco:Macro>

    macro param: alias=sourcePath  name=sourcePath  type=text

    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet...>

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

    <ul>
      <xsl:for-each select="/macro/sourcePath">
          more code
      </xsl:for-each>
    </ul>

    </xsl:template>
    </xsl:stylesheet>


    did i set this up properly?

    thanks for any help

     

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Feb 17, 2011 @ 17:16
    Simon Dingley
    0

    You don't need a parameter if you are going to use $currentPage because you can do that directly in your macro.

    E.g.

     

    <xsl:for-each select="$currentPage/Posts/Year/Month/*">
          more code
    </xsl:for-each>

    That said, if you are passing in a node as the source path you want the parameter type to perhaps be a content picker and then use:

    <xsl:variable name="source" select="/macro/sourcePath" />
    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)">
          more code
    </xsl:for-each>

     

  • David Cardine 7 posts 27 karma points
    Feb 18, 2011 @ 15:35
    David Cardine
    0

    Thanks for the feedback. I ended up changing my plan like 100 times it felt like. new to xsl & umbraco and it's... fun in a crazy sort of way. I was able to get my page working with what you provided, but i ended up changing it b/c of needed to do something else.

     

    thanks again!

Please Sign in or register to post replies

Write your reply to:

Draft