Search code examples
xmltemplatesxsltparameterssubroutine

XSL sub routine parameter not displaying


I'm writing an XSLT to do some error checking on an XML, and I'm passing the Tag/element as a parameter to a subroutine, but I'm having trouble displaying the parameter on the error message.

I don't understand why the following doesn't display $param1 (or why its empty).

Code is as follows:

I tried with select="string($param1)" and just select="$param1"

<!-- ABOUT_VERSION level -->
<xsl:template match="m:ABOUT_VERSION">
    <xsl:call-template name="TagCheckCount">
        <xsl:with-param name="param1" select="m:CreatedDatetime"/>
        <xsl:with-param name="param2" select="1"/>
        <xsl:with-param name="param3" select="1"/>
    </xsl:call-template>
</xsl:template>

<!-- Check The Numbers of Tags that exist -->   
<xsl:template name="TagCheckCount">
    <xsl:param name="param1"/> <!-- Tag -->
    <xsl:param name="param2"/> <!-- Lower Bound -->
    <xsl:param name="param3"/> <!-- Upper Bound -->

    <xsl:choose>
        <!-- If Lower and Upper Bounds are 1 -->
        <xsl:when test="$param2 = 1 and $param3 = 1">
            <!-- Check if it exists -->
            <xsl:call-template name="TagCheckExists">
                <xsl:with-param name="param1" select="$param1"/>
            </xsl:call-template>
        </xsl:when>
        <!-- Else If -->
        <xsl:otherwise>
            <!-- Count is < Lower Bound -->
            <xsl:call-template name="TagCheckLT">
                <xsl:with-param name="param1" select="$param1"/>
                <xsl:with-param name="param2" select="$param2"/>
            </xsl:call-template>
            <!-- Count is > Upper Bound -->
            <xsl:call-template name="TagCheckGT">
                <xsl:with-param name="param1" select="$param1"/>
                <xsl:with-param name="param2" select="$param2"/>
            </xsl:call-template>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


<!-- Check if Tag exists -->
<xsl:template name="TagCheckExists">
    <xsl:param name="param1"/> <!-- Tag -->

    <xsl:value-of select="string($param1)" /><br/><br/><br/>

    <!-- Check if it exists -->
    <xsl:if test="not($param1)">
        <!-- Return Error Message and XPath -->
        <p class="error">Requirement: Missing: <xsl:call-template name="GetFullPath"/><xsl:value-of select="string($param1)" /></p>
    </xsl:if>
</xsl:template>

Solution

  • The answer is:

    When passing a STRING, you MUST include the string in single quotes inside the double quotes as such:

    Otherwise: The answer here is that because the element of param1 does not exist, then it's stringing the information in the element (which doesn't exist) so it's literally displaying nothing, correctly.