xml - 如何使用 XSLT 编写多个 when 条件?
问题描述
我试图在满足 3 个条件时获得响应,否则它应该拒绝并生成失败响应。以下是我的示例输入:
<Message>
<Header>
<Role actionCode="04">
<RoleCode>BM01</RoleCode>
</Role>
<Role actionCode="04">
<RoleCode>CM011</RoleCode>
</Role>
<Common>
<tag>Data</tag>
<tag2>Data2</tag2>
<Pstatus>111</Pstatus>
</Common>
</Header>
</Message>
我把条件写成
<xsl:when test="$RoleCode = 'BM01 and CM011' and $Pstatus='111 OR 112' ">
<xsl:value-of select="$tag"/>
<xsl:when test="$RoleCode = 'BM02 and CM011' and $Pstatus='111 OR 112' ">
<xsl:value-of select="$tag2"/>
<xsl:when test="$Pstatus='101' ">Reject
<xsl:otherwise>Reject</xsl:otherwise>
当角色代码与BM01/BM02 和CM011 以及Pstatus 为111 或112 匹配时,它应该复制数据,如果pstatus 是101 接收到,它应该拒绝。我只收到拒绝消息作为输出,但条件没有执行。有人可以帮忙吗?
解决方案
我猜(!)你想做类似的事情:
<xsl:template match="Message">
<xsl:variable name="RoleCode" select="Header/Role/RoleCode" />
<xsl:variable name="Pstatus" select="Header/Common/Pstatus" />
<xsl:variable name="tag" select="Header/Common/tag" />
<xsl:variable name="tag2" select="Header/Common/tag2" />
<xsl:choose>
<xsl:when test="$RoleCode='BM01' and $RoleCode='CM011' and ($Pstatus='111' or $Pstatus='112')">
<xsl:value-of select="$tag"/>
</xsl:when>
<xsl:when test="$RoleCode='BM02' and $RoleCode='CM011' and ($Pstatus='111' or $Pstatus='112')">
<xsl:value-of select="$tag2"/>
</xsl:when>
<xsl:otherwise>Reject</xsl:otherwise>
</xsl:choose>
</xsl:template>
推荐阅读
- android - 片段类中的 TimePickerDialog
- linux - 为什么命令在运行之前会被 Bash 扩展?
- c++ - 用 2 个指针反转链表
- c# - Web API 在响应中给出异常
- javascript - Using Webworkers in angular app (service worker cache access of data in angular-cli)
- javascript - iframe 内的基本网址无法正常工作
- ssl - 如何在 nginx 中设置 websocket 代理和 cors?
- graphql - 在一个查询中组装 graphql 查询,而无需重新编写解析器或定义
- c# - 使用 c# 检查文件中出现的两行
- django - django modelform 覆盖 save() 方法 self.instance 已更改