<c:choose>、<c:when> ||<c:otherwise>

本文介绍如何使用EL表达式中的<c:choose>、<c:when>及<c:otherwise>标签来实现条件分支逻辑,类似于Java中的if-else语句。通过具体例子展示了不同条件下的内容输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


<c:choose> 和 <c:when> 、 <c:otherwise> 一起实现互斥条件执行,类似于 java 中的 if else.
<c:choose> 一般作为 <c:when> 、 <c:otherwise> 的父标签。
eg :
<c:choose>
       <c:when test="${row.v_money<10000}">
              初学下海

       </c:when>

       <c:when test="${row.v_money>=10000&&row.v_money<20000}">
              身手小试

       </c:when>

       <c:otherwise>
              商业能手

       </c:otherwise>

</c:choose>
&lt;xsl:template match=“w:tc”> &lt;fo:table-cell border=“1pt solid black” padding=“2pt” display-align=“center”> &lt;xsl:variable name=“totalCols” select=“count(ancestor::w:tbl/w:tblGrid/w:gridCol)”/> &lt;xsl:variable name=“precedingSpanSum”> xsl:choose &lt;xsl:when test=“preceding-sibling::w:tc”> &lt;xsl:value-of select=“sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val) + count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])”/> &lt;/xsl:when&gt; xsl:otherwise0&lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:variable> &lt;xsl:if test=“w:tcPr/w:gridSpan”> &lt;xsl:variable name=“declaredSpan” select=“w:tcPr/w:gridSpan/@w:val”/> &lt;xsl:variable name=“remainingCols” select=“$totalCols - $precedingSpanSum”/> &lt;xsl:attribute name=“number-columns-spanned”> xsl:choose &lt;xsl:when test=“$declaredSpan > $remainingCols”> &lt;xsl:value-of select=“$remainingCols”/> &lt;/xsl:when&gt; xsl:otherwise &lt;xsl:value-of select=“$declaredSpan”/> &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:attribute> &lt;/xsl:if> &lt;xsl:if test="w:tcPr/w:vMerge[@w:val='restart']"> &lt;xsl:variable name="currentPos" select="count(preceding-sibling::w:tc) + 1"/> &lt;xsl:variable name="rowSpan"> &lt;xsl:call-template name="calculateRowSpan"> &lt;xsl:with-param name="remainingRows" select="../following-sibling::w:tr"/> &lt;xsl:with-param name="position" select="$currentPos"/> &lt;xsl:with-param name="count" select="1"/> &lt;/xsl:call-template> &lt;/xsl:variable> &lt;xsl:attribute name="number-rows-spanned"> &lt;xsl:value-of select="$rowSpan"/> &lt;/xsl:attribute> &lt;/xsl:if> &lt;fo:block linefeed-treatment="ignore" white-space-collapse="true"> &lt;xsl:apply-templates select=".//w:p"/> &lt;/fo:block> &lt;/fo:table-cell> &lt;/xsl:template> &lt;!-- 新增递归模板 --> &lt;xsl:template name="calculateRowSpan"> &lt;xsl:param name="remainingRows"/> &lt;xsl:param name="position"/> &lt;xsl:param name="count"/> &lt;xsl:choose&gt; &lt;xsl:when test="count($remainingRows) = 0"> &lt;xsl:value-of select="$count"/> &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:variable name="currentRow" select="$remainingRows[1]"/> &lt;xsl:variable name="targetCell" select="$currentRow/w:tc[$position]"/> &lt;xsl:variable name="precedingSpan" select="sum($currentRow/w:tc[position() &lt; $position]/w:tcPr/w:gridSpan/@w:val)"/> &lt;xsl:choose&gt; &lt;xsl:when test="$targetCell/w:tcPr/w:vMerge[@w:val='continue'] and ($position - $precedingSpan) &lt;= count($currentRow/w:tc)"> &lt;xsl:call-template name="calculateRowSpan"> &lt;xsl:with-param name="remainingRows" select="$remainingRows[position() > 1]"/> &lt;xsl:with-param name="position" select="$position"/> &lt;xsl:with-param name="count" select="$count + 1"/> &lt;/xsl:call-template> &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="$count"/> &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template>上述样式表中合并单元格有问题,你检查一下给出修改好的结果,一定要注意这是word的xml转xls-fo的xlst样式表,且xsl和xml版本均为1.0,请直接给出修改结果
最新发布
03-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值