我的xml文档中有以下元素
<LivesWithIndicator>true</LivesWithIndicator>
我希望当LivesWithIndicator为true时显示以下内容
<xsl:text>Juvenile lives with this Parent/Guardian/Custodian</xsl:text>
**否则当**
<LivesWithIndicator>false/LivesWithIndicator>
显示
<xsl:text>Juvenile does not live with this Parent/Guardian/Custodian</xsl:text>
我的xsl代码
<xsl:value-of select="LivesWithIndicator"/>
显示
Juvenile lives with this Parent/Guardian/Custodian: true
这不是我想要的
答案 0 :(得分:1)
您可以在这里使用xsl:choose
<xsl:choose>
<xsl:when test="LivesWithIndicator='true'">
<xsl:text>Juvenile lives with this Parent/Guardian/Custodian</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Juvenile does not live with this Parent/Guardian/Custodian</xsl:text>
</xsl:otherwise>
</xsl:choose>
或者,您可以使用基于模板的方法。像这样创建两个模板:
<xsl:template match="LivesWithIndicator[. = 'true']">
<xsl:text>Juvenile lives with this Parent/Guardian/Custodian</xsl:text>
</xsl:template>
<xsl:template match="LivesWithIndicator">
<xsl:text>Juvenile does not live with this Parent/Guardian/Custodian</xsl:text>
</xsl:template>
然后你可以这样做来输出值
<xsl:apply-templates select="LivesWithIndicator" />