我有以下 XML,需要有条件地过滤 UnitOfMeasure 是否有值。如果 ID = 'AcceptanceCriterionValue1' 的第一个 UnitOfMeasure 包含长度大于 0 的字符串,我应该选择该值。否则,我需要选择 ID = 'AcceptanceCriterionValue2' 的 UnitOfMeasure 节点值。换句话说,如果 pH1 存在,抓住它。否则抓取 pH2:
`
<MaterialLots>
<MaterialLotProperty>
<ID>AcceptanceCriterionValue1</ID>
<Value>
<ValueString>5</ValueString>
<UnitOfMeasure>pH1</UnitOfMeasure>
</Value>
</MaterialLotProperty>
<MaterialLotProperty>
<ID>AcceptanceCriterionValue2</ID>
<Value>
<ValueString>7</ValueString>
<UnitOfMeasure>pH2</UnitOfMeasure>
</Value>
</MaterialLotProperty>
</MaterialLots>
`
而且我需要执行以下逻辑。当 pH1 存在时,第一个 xsl:when 语句成功,但如果它为空,则 xsl:otherwise 会触发但由于某种原因不返回 pH2:
`
<xsl:choose>
<xsl:when test="ns:MaterialLots/ns:MaterialLotProperty/ns:ID='AcceptanceCriterionValue1' and string-length(ns:MaterialLots/ns:MaterialLotProperty/ns:Value/ns:UnitOfMeasure) > 0">
<xsl:value-of select="ns:MaterialLots/ns:MaterialLotProperty/ns:Value/ns:UnitOfMeasure" />
</xsl:when>
<xsl:otherwise>
<xsl:if test="ns:MaterialLots/ns:MaterialLotProperty/ns:ID='AcceptanceCriterionValue2' and string-length(ns:MaterialLots/ns:MaterialLotProperty/ns:Value/ns:UnitOfMeasure) > 0">
<xsl:value-of select="ns:MaterialLots/ns:MaterialLotProperty/ns:Value/ns:UnitOfMeasure" />
</xsl:if>
</xsl:otherwise>
</xsl:choose>
`