Copied to clipboard

Flag this post as spam?

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


  • Streety 358 posts 568 karma points
    Mar 01, 2012 @ 11:48
    Streety
    0

    Passing a Parameter Variable to $currentPage

    Hello.

    I have a syntax issue. I am trying to pass a parameter with my macro to XSLT and it doesn't like it.

    I have a series of content panels and the current page looks for a value. At the momemt it works if I hard encode the name of the content panel:

    <xsl:variable name="nodeIds" select="umbraco.library:Split($currentPage/contentpanels,',')" />

    But I want this name to come from a passed parameter so that I can have multiple panels that are different without having mutiple XSLT scripts.

    I have added the parameter value:

        
    <xsl:param name="cPanel" select="/macro/CPID" />

    <xsl:template match="/">

    <xsl:if test="string-length($currentPage/$cPanel > 0">
    <xsl:variable name="nodeIds" select="umbraco.library:Split($currentPage/$cPanel,',')" />

    The parameter is passing the value properly but it fails. I could do with a hand with the syntax.

     

    Thank you.

    <?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:param name="cPanel" select="/macro/CPID" />

    <xsl:template match="/">

    <xsl:if test="string-length($currentPage/$cPanel > 0">
    <xsl:variable name="nodeIds" select="umbraco.library:Split($currentPage/$cPanel,',')" />
    <xsl:if test="count($nodeIds/value) > 0">
    <ul>
    <xsl:for-each select="$nodeIds/value">
    <li>
    <xsl:value-of disable-output-escaping="yes" select="umbraco.library:RenderTemplate(current()/.,umbraco.library:GetXmlNodeById(current()/.)/@template)"/>
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Mar 01, 2012 @ 12:37
    Chriztian Steinmeier
    0

    Hi Streety,

    You can set the cPanel variable to the node right away:

    <xsl:variable name="cPanel" select="$currentPage/*[name() = /macro/CPID]" />
    

    Then you can just ask for its existence:

    <xsl:if test="$cPanel">
       <xsl:variable name="nodeIds" select="umbraco.library:Split($cPanel, ',')" />
       <xsl:if test="$nodeIds/value">
       ... etc ...

    /Chriztian

  • Streety 358 posts 568 karma points
    Mar 01, 2012 @ 14:26
    Streety
    0

    Thanks for that.

    <xsl:variable name="nodeIds" select="umbraco.library:Split($cPanel, ',')" />

    This worksif I setup the variable manually...ie:

    <xsl:variable name="cPanel" select="$currentPage/contentPanels" />

    but not as you have suggested

    <xsl:variable name="cPanel" select="$currentPage/*[name() = /macro/CPID]" />

    it is passing the parameter in the masterpage

     <umbraco:Macro CPID="contentPanels" Alias="[XSLT]ContentPanels" runat="server"></umbraco:Macro>

    and the macro has a CPID parameter set to show with its type set to Text.

     

    Not sure what else to try.

Please Sign in or register to post replies

Write your reply to:

Draft