开发者

Test param value type in XSL

I am getting this from LibXSLT:

XSLTProcessor::transformToXml(): Invalid type
XSLTProcessor::transformToXml(): xmlXPathCompiledEval: 1 objects left on the stack.

I am passing a param which can either have a string value or a nodeset. I am trying to test whether it contains a certain substring and in that case assign that value to another parameter.

The calling template:

<xsl:call-template name="img">
    <xsl:with-param name="upload" select="'url.com/image.jpg'"/>
    <xsl:with-param name="w" select="200"/>
    <xsl:with-param name="h" select="200"/>
</xsl:call-template>

The called template:

<xsl:template name="img" match="*" mode="w">
    <xsl:param name="upload" select="."/>

    <xsl:param name="JITexternal">
        <xsl:choose>
            <xsl:when test="
                not($upload/meta) and (contains($upload, '.jpg')
                or
                contains($upload, '.png'))
                ">
                <xsl:value-of select="$upload"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="0"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
</xsl:template>

While I am not sure what is tripping LibXSLT, I think is that fact that when I run those tests and the value is a string it throws the type error above.

But most importantly,开发者_Python百科 is there a good way to test the type of a param's value?

UPDATE: the full XSL script on GitHub


While not exactly type checking, I found that converting the result tree fragment to a string() before running my test did prevent LibXSLT to bomb out:

    <xsl:param name="JITexternal">
        <xsl:choose>
            <xsl:when test="starts-with(string($upload), 'http://')">
                <xsl:value-of select="$upload"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="0"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:param>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜