Copied to clipboard

Flag this post as spam?

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


  • Ben Norman 167 posts 276 karma points
    Jan 12, 2012 @ 22:27
    Ben Norman
    0

    call different xslt based on request

    I would like to call a different macro based on whether a querystring parameter exists or not. Can you do this in the template.

    Here is the pseudo cod

    If the category parameter exists and has a value in the querystring then

    display xslt1

    else

    display xslt2

    Can this be done?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 12, 2012 @ 23:49
    Jan Skovgaard
    0

    Hi Ben

    Yes that can be done.

    You should be able to create two templates, which you can store seperately and then include them in a third xslt file where you check the parameter and decide, which template to serve.

    You can also have more templates in the same file and decide, which one to call dependant on the request parameter.

    You could have something like this

    <xsl:template match="/">

    <xsl:choose>
    <xsl:when test="umbraco.library:Request('param')" ='myvalue'>
    <xsl:call-template name="template1" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:call-template name="template2" />
    </xsl:otherwise>
    </xsl:choose>

    </xsl:template>

    <xsl:template name="template1">
    <!-- code for template 1 here -->
    </xsl:template>

    <xsl:template name="template2">
    <!-- code for template 2 here -->
    </xsl:template>

    Hope this helps :)

    /Jan

  • Ben Norman 167 posts 276 karma points
    Jan 13, 2012 @ 02:39
    Ben Norman
    0

    ok cool, if I read it right then your saying just do it in a "macro" and not in the template, no worries and thanks.

    so, can you call a macro from xslt? ie create a macro that refers to a different xslt or razor file and call it from this xslt.

    or can you call another xslt from this xslt? ie put template1 in a different xslt file and call it from here.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 13, 2012 @ 08:10
    Jan Skovgaard
    0

    Hi Ben

    As I also mentioned above it is possible to include other XSLT files in each other, so you can easily save the above templates in 2 different xslt files, which you then can include or import into your third XSLT file where you handle the logic.

    Yo can read more about xsl:include and xsl:import here: http://xml.apache.org/xalan-j/xsltc/xsl_include_design.html

    If I get your question correct there is no need to call a macro from XSLT - but if you need to then yes it's possible to do using the umbraco.library:RenderMacroContent() extension.

    Hope this helps.

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft