Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT if expression syntax, combining more than one expression

Tags:

xml

xslt

xpath

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.

like image 429
mswieboda Avatar asked May 15 '12 16:05

mswieboda


1 Answers

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).

like image 108
Maestro13 Avatar answered Sep 18 '22 04:09

Maestro13