Copied to clipboard

Flag this post as spam?

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


  • David F. Hill 122 posts 242 karma points
    Nov 11, 2009 @ 23:50
    David F. Hill
    0

    XSLT parameter not being displayed

    Hello Umbraco colleagues:

    I can't figure out why this simple xslt will not display the value of the parameter being passed to it.

    I'd like to use the technique to improve code reuse.

    The template "secTemplate" will display the text, "Parm A:" but not the value of parmA.

    I'm sure it must be simple but I'm not seeing it.

    Thanks!

    David Hill

    Here's the xslt:

     

    <?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" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
        exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>

    <xsl:template match="/">
        <xsl:call-template name="secTemplate">
        <xsl:with-param name="parmA" select="abcdef" />
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="secTemplate">
        <xsl:param name="parmA" />
        <xsl:text>Parm A:</xsl:text>
        <xsl:value-of select="$parmA" />    <!-- this is not being displayed -->
    </xsl:template>

    </xsl:stylesheet>

     

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    Nov 12, 2009 @ 00:13
    Chris Houston
    0

    Hi David,

    Your string needs to be in single quotes for it to be recognised as a string.

    I.e. Change this line:

        <xsl:with-param name="parmA" select="abcdef" />

    To this:

        <xsl:with-param name="parmA" select="'abcdef'" />

    And you will see it works :)

    And the complete copy of your XSLT with the change:

    <?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" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:call-template name="secTemplate">
    <xsl:with-param name="parmA" select="'abcdef'" />
    </xsl:call-template>
    </xsl:template>

    <xsl:template name="secTemplate">
    <xsl:param name="parmA" />
    <xsl:text>Parm A:</xsl:text>
    <xsl:value-of select="$parmA" /> <!-- this is not being displayed -->
    </xsl:template>

    </xsl:stylesheet>

    Also try changing the with-param statement to this:

        <xsl:with-param name="parmA" select="$currentPage/@nodeName" />

    And then you will see the node name output in your secTemplate.

    Cheers,

    Chris

  • David F. Hill 122 posts 242 karma points
    Nov 12, 2009 @ 01:10
    David F. Hill
    0

    Chris,

    Thank you. That was precisely the issue.

    Once again you have resolved my issue - and so promptly!

    Obviously, my use for this is more complex. I intend to place my frequently used logic in generic in xslt files. Any customization needed will be in other xslt files and I'll reference the generic ones passing parameters as needed.

    I learned I can reference external xslt files by adding this to the calling one:

    <xsl:include href="secondaryTemplate.xslt" />

    Thanks again!

    David

Please Sign in or register to post replies

Write your reply to:

Draft