SalH
SalH

Reputation: 91

how to evaluate variables in xslt messages when run on MarkLogic

I have a xslt that is evaluated in Marklogic (via xdmp:xslt-invoke). I am trying to evaluate a variable inside a xsl:message tag, however, when Marklogic encounters the message, it doesn't evaluate the variable, but simply displays the text inside it.

For example:

<xsl:template match="/">
    <xsl:variable name="x" select="//xpath"/>
    <xsl:message terminate="yes">Terminating <xsl:value-of select="$x"/></xsl:message>        
</xsl:template>

When this is evaluated, I see something like this in the output:

[XSLT] XSLT-MSGTERMINATE: (err:XTMM9000)<xsl:message terminate="yes"><xsl:text>"Terminating "</xsl:text><xsl:value-of select="$x"/><xsl:text>"&#10; />"</xsl:text></xsl:message> -- xsl:message instruction called with terminate

Is there a way to actually evaluate and display the value of $x in the message?

Upvotes: 3

Views: 1616

Answers (1)

SalH
SalH

Reputation: 91

While xsl:message terminate="yes" wasn't evaluating the variables. I was able to evaluate the variables through xdmp:eval in the following way and present the termination message as a fn:error

<xsl:template match="//some xpath condition">
    <xsl:variable name="x" select="//someXpath string value"/>
        <xsl:message terminate="yes">
        <xsl:value-of
            select="
                xdmp:eval(concat(
                'xquery version ''1.0-ml'';',
                'let $message := concat(''Terminating with value ''', ',', '''', $x, ''')',
                'let $_error := error(xs:QName(''Error''), $message)',
                'return $_error'
                ))"
        /></xsl:message></xsl:template>

The following xdmp:eval will evaluate the $x variable value correctly.

Upvotes: 1

Related Questions