I have the following XML and need to filter conditionally on whether or not UnitOfMeasure has a value. If the first UnitOfMeasure where ID = 'AcceptanceCriterionValue1' contains a string with a length greater than 0, I should select that value. Otherwise, I need to select the UnitOfMeasure node value where ID = 'AcceptanceCriterionValue2'. In other words, if pH1 exists, grab it. Otherwise grab 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>
`
And I need to perform the following logic. The first xsl:when statement succeeds when pH1 exists, but if it's empty the xsl:otherwise fires but doesn't return pH2 for some reason:
`
<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>
`