tags:

views:

35

answers:

3

Can you nest xsl:if within nested xsl:when, for example:

    <xsl:choose>
        <xsl:when test="param/@id  =  '1' " >
            <xsl:if test="param/value = 'XML' ">
                <xsl:when test="param/@id = '2' ">
                    <xsl:if test="param/value = 'HTTP' ">
                        <xsl:when test="param/@id = '3' ">
                            <xsl:if test="param/value = 'Y' ">
                                <xsl:call-template name="buildPayload"/>
                            </xsl:if>
                        </xsl:when>
                    </xsl:if>
                </xsl:when>
            </xsl:if>
        </xsl:when>
    </xsl:choose>

Can this be used, or is there away to streamline this into a more compact code?

A: 

Yeah this looks like it will not work. You could add "and"s and "or"s in the test for the when.

Kramer
A: 

You may want to read up on XPath. You should be able to use XPath Expressions and the Node Selection syntax to help with this selection.

You may also try to use a visual XSLT designer such as the tooling in Visual Studio. Visual Studio, for example, will provide IntelliSense and validation for XSLT.

Matthew Whited
+3  A: 

Without trying it: I'd think that <xsl:when> cannot be a child node of <xsl:if> without another <xsl:choose> in between. But, what are you trying to do? If I see that right, you want to run <call-template> if and only if (param/@id='1' and param/value='XML') or (param/@id='2' and param/value='HTTP') or (param/@id='3' and param/value='Y') ... try that as the test value:

<xsl:if test="(param/@id='1' and param/value='XML') or (param/@id='2' and param/value='HTTP') or (param/@id='3' and param/value='Y')">
    <xsl:call-template name="buildPayload"/>
</xsl:if>
maligree