Subject: [xsl] Checking if a variable has a value From: "Mark Giffin m1879@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 31 Aug 2022 01:27:13 -0000 |
XSLT 2.0, Saxon processor. What's a good way to check if a variable has a value? I want to print something if a variable has a value, and not print it if it is not given a value. This must be extremely simple but I don't see it. Variable is declared: <xsl:param name="git-hash"/> This will sometimes be given a string value like this: 26166cf7f809f5107778c2742e06edb024c5ffef I tried this and others: <xsl:if test="matches($git-hash, '\d|[a-z]')"> <dc:subject>git hash: <xsl:value-of select="$git-hash"/></dc:subject> </xsl:if> When the variable has no value, the following is output instead of nothing: git hash: ${git-hash} The following works but only if the value has numbers in it: <xsl:if test="matches($git-hash, '\d')"> None of these work, what have I missed: <xsl:if test="$git-hash"> <xsl:if test="boolean($git-hash)"> <xsl:if test="matches($git-hash, '\d|\S')"> <xsl:if test="matches($git-hash, '\d|[a-z]')"> <xsl:choose> <xsl:when test="not($git-hash)"></xsl:when> <xsl:otherwise> <dc:subject>git hash: <xsl:value-of select="$git-hash"/></dc:subject> </xsl:otherwise> </xsl:choose> Thanks, Mark
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Looking for a cleaner way, Trevor Nicholls trev | Thread | Re: [xsl] Checking if a variable ha, Bauman, Syd s.bauman |
Re: [xsl] Looking for a cleaner way, Trevor Nicholls trev | Date | Re: [xsl] Checking if a variable ha, Bauman, Syd s.bauman |
Month |