Tutorial :nested &


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?


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>  


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »