Copied to clipboard

Flag this post as spam?

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


  • Kevon K. Hayes 255 posts 281 karma points
    Aug 23, 2010 @ 18:35
    Kevon K. Hayes
    0

    Dynamically Passing a Property Value to an XSLT macro

    I have this working perfectly:

    <xsl:template match="/">
    <ul class="menuItem">
      <xsl:for-each select="umbraco.library:GetXmlNodeById(1321)/corDeptMenuItem [@isDoc]">
               
        <li><a href="{umbraco.library:NiceUrl(corDeptMenuItemLink)}"><xsl:value-of select="@nodeName"/></a></li>
               
      </xsl:for-each>
    </ul>
    </xsl:template>

    However I'd like to pass the value of my "Menu Items ID" property (alias=menuItemsID) into the GetXMLNodeById function. So the ID is dynamicall fetched.

    I've tried 2 ways from a previous forum and a WIKI page but to no avail (I wonder do I need to wait for UMB caching to recognize new property?)

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 23, 2010 @ 20:57
    Kevon K. Hayes
    0

    I've tried this:

     

    <xsl:template match="/">
    <ul class="menuItem">
      <xsl:for-each select="umbraco.library:GetXmlNodeById(data [@alias = 'corMenuItemsID'])/corDeptMenuItem [@isDoc]">
               
        <li><a href="{umbraco.library:NiceUrl(corDeptMenuItemLink)}"><xsl:value-of select="@nodeName"/></a></li>
               
      </xsl:for-each>
    </ul>
    </xsl:template>

    but id didn't work...
    I've tried this:

    <umbraco:Macro Alias="ListCustomNodeItems" menuID="[#corMenuItemsID]" runat="server"></umbraco:Macro>

    with this

    <xsl:template match="/">
    <ul class="menuItem">
      <xsl:for-each select="umbraco.library:GetXmlNodeById(data [@alias = 'corMenuItemsID'])/corDeptMenuItem [@isDoc]">
               
        <li><a href="{umbraco.library:NiceUrl(corDeptMenuItemLink)}"><xsl:value-of select="@nodeName"/></a></li>
               
      </xsl:for-each>
    </ul>
    </xsl:template>

    and that didn't work.  Not too sure from here.

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 23, 2010 @ 21:07
    Kim Andersen
    1

    I guess that you have the corMenuItemsID-property (or is it menuItemsID as you mentioned in your first post?) on the current page? If you do could you maybe try this out:

    <xsl:template match="/">
    <xsl:variable name="id" select="$currentPage/
    corMenuItemsID" />
    <ul class="menuItem">
     
    <xsl:for-each select="umbraco.library:GetXmlNodeById($id)/corDeptMenuItem [@isDoc]">
               
       
    <li><a href="{umbraco.library:NiceUrl(corDeptMenuItemLink)}"><xsl:value-of select="@nodeName"/></a></li>
               
     
    </xsl:for-each>
    </ul>
    </xsl:template>

    /Kim A

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 23, 2010 @ 21:24
    Kevon K. Hayes
    0

    I received the following error below, do I have to create a parameter for this macro first in the Developer Section? Also I'm on 4.5.1 if this matters.

    Error occured

    System.Xml.Xsl.XslLoadException: The variable or parameter 'currentPage' is either not defined or it is out of scope. An error occurred at C:\inetpub\wwwroot\xslt\634181701810191856_temp.xslt(13,5).
    at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
    at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 23, 2010 @ 21:31
    Kim Andersen
    0

    Hmm...Did you not create this xslt-file through Umbraco? If you didn't could you please insert the following snippet just above the <xsl:template match="/"> :

    <xsl:param name="currentPage"/>

    It's a good idea to create your XSLT-files through Umbraco (especially in the beginning when you are still learning about the CMS) because you'll then alway have access to the $currentPage, umbraco.library etc. without doing anything.

    /Kim A

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 23, 2010 @ 21:33
    Kevon K. Hayes
    0

    I have that, I didn't create a Parameter for the Macro.  Is that the missing link?

    <?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"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <ul class="menuItem">
      <xsl:for-each select="umbraco.library:GetXmlNodeById(1321)/corDeptMenuItem [@isDoc]">
               
        <li><a href="{umbraco.library:NiceUrl(corDeptMenuItemLink)}"><xsl:value-of select="@nodeName"/></a></li>
               
      </xsl:for-each>
    </ul>
    </xsl:template>

    </xsl:stylesheet>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 23, 2010 @ 21:39
    Kim Andersen
    0

    Well, if you are grabbing the "Menu Items ID" through the xslt I provided earlier, you don't need the macro parameter called menuID. You can remove that parameter from the macro (if you even created it) and from the line where you insert the macro in the template.

    /Kim A

  • Kevon K. Hayes 255 posts 281 karma points
    Aug 23, 2010 @ 21:44
    Kevon K. Hayes
    0

    That worked.  Thanks a million. May your Karma increase 100 fold.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Aug 23, 2010 @ 21:45
    Kim Andersen
    0

    Good to hear Kevon! Glad I could help :)

    /Kim A

  • William Schwartz 16 posts 85 karma points
    Jan 30, 2011 @ 17:54
    William Schwartz
    0

    Kim,

    I was researching a similar issue and your solution helped a bunch. Thanks!

    -Wm

  • Kevon K. Hayes 255 posts 281 karma points
    Jan 30, 2011 @ 19:26
    Kevon K. Hayes
    0

    Also make sure your content nodes are republished if you change the propertiy names on your documenttypes.  This caused much confusion when my code was right, but didnt get the expected results.  It was due to outdated xml cache.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 30, 2011 @ 20:51
    Kim Andersen
    0

    I'm glad you can use the answer William. It's just great when "old" answers helps people out several months after they where posted :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft