mswieboda
mswieboda

Reputation: 1026

XSLT if expression syntax, combining more than one expression

Trying to combine an if statement using <xsl:if test="expression"> where I want to have multiple expressions together, to do order of operations such as this psuedocode:

if (Number != '' and (Name != '' or PreferredName != '')) {// code here}

Essentially I want to do this in an <xsl:if>:

<xsl:if text="Number != '' and (Name != '' or PreferredName != '')">

but I'm not sure of the expression syntax, I don't think I can do the () like that, as I haven't seen it anywhere. I couldn't find the expression syntax on the web easily, it may be XPath, but I'm not sure if XPath supports () to group expressions. I'm not an expert on XSL/XML/XSD's' so I don't know if the expression is even XPath, or what.

I'd rather not do nested <xsl:if> statements if possible, and want to stick with <xsl:if> not <xsl:choose>.

I'm sure this is probably a simple answer, but kind of stuck here. Thanks.

Upvotes: 10

Views: 30962

Answers (1)

Maestro13
Maestro13

Reputation: 3696

The conditional statement xsl:if for starters needs an xsl:template or other xsl element as parent.
The syntax will become similar to the following:

<xsl:template>
    ... preliminary xsl statements ...
    <xsl:if test="Number != '' and (Name != '' or PreferredName != '')">
        ... further xsl statements (the code you were referring to ...
    </xsl:if>
    ... other xsl stataments ...
</xsl:template>

Further advise: study xslt usage, in particular templates and their application (and sort of automatic looping).

Upvotes: 12

Related Questions