Search code examples
xsltxslt-2.0xsl-fo

XSL Two Conditions Expression If Test


I can get my 2 expressions to process as I want with:

<xsl:if test="string-length(.) > 15">
    <xsl:if test="not(contains(., ' '))">
        <xsl:attribute name="font-size">5pt</xsl:attribute>
    </xsl:if>
</xsl:if>

however I'm not clear why I can't just write it as one test:

<xsl:if test="string-length(.) > 15 && not(contains(., ' '))">
    <xsl:attribute name="font-size">5pt</xsl:attribute>
</xsl:if>

this throws back an unknown error with my processor (Apache XSL FO).

I'm trying to test the current node I'm in to see if it contains more than 15 characters and no white space. If that match is met I reduce the font size to 5pt.


Solution

  • The expression language used in XSLT is XPath, in XSLT 2.0 it is XPath 2.0. The boolean and operator just has the English name so string-length(.) > 15 and not(contains(., ' ')) is all you need.