2012-08-06 43 views
0

我是很新的XSLTXSLT嵌套条件 - 如何做到这一点

我有以下XSLT片段(pseudo'ed为清楚起见):

<xsl:for-each select="fields/field"> 
    <xsl:if test="field=someThing"> 
    <div> 
     <!--some content output--> 
     <!--here by doing--> 
     <!--some complex stuff--> 
    </div> 
    </xsl:if> 
</xsl:for-each> 

但根据从现场的价值循环,我可以选择在结束div之前做一些其他的事情。

所以(手持闪亮的新XSL的书)我想我可以做这样的事情:

<xsl:for-each select="fields/field"> 
    <xsl:if test="field=someThing"> 
    <div> 
     <!--some content output--> 
     <!--here by doing--> 
     <!--some complex stuff--> 
    <xsl:choose> 
     <xsl:when test="field=someThingSpecific"> 
     <div> 
     <!--process some additional--> 
     <!--stuff here--> 
     </div> 
     <!--then close div--> 
     </div> 
     </xsl:when> 
     <xsl:otherwise> 
     <!--nothing to do here--> 
     <!--just close the div--> 
     </div> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:if> 
</xsl:for-each> 

但它炸毁。

显然是因为结束div已经进入有条件的xsl:选择阻止

所以2个问题真的:

为什么犯规它当作是工作的?

我该如何实现我的目标?

回答

0

这是因为你的XSLT格式不正确而炸毁的。当您打开xsl:choose之外的第一个div时,您必须在xsl:choose之外关闭它。

另外,如果你不需要做任何事情在你的xsl:otherwise,刚做了另外xsl:if

<xsl:for-each select="fields/field"> 
    <xsl:if test="field=someThing"> 
     <div> 
      <!--some content output--> 
      <!--here by doing--> 
      <!--some complex stuff--> 
      <xsl:if test="field=someThingSpecific"> 
       <div> 
        <!--process some additional--> 
        <!--stuff here--> 
       </div> 
      </xsl:if> 
      <!--then close div--> 
     </div> 
    </xsl:if> 
</xsl:for-each> 
+0

啊,我刚睡醒了“durrhhh时刻”。谢谢澄清 – bule 2012-08-06 07:10:50