输入 XML:
<Response>
<Quote qtID="5443655">
<Incidents>
<Incident name="Subway1" active="true" primary="false" ActivityID="32">
<IncidentConfig>
<AccountID>CCCCCCCC</AccountID>
</IncidentConfig>
<cals>
<cal name="PMP" value="32.0">
</cal>
<cal name="TC" value="85.83612">
</cal>
<cal name="D" value="70.83612">
</cal>
</cals>
</Incident>
<Incident name="Subway2" active="true" primary="true" ActivityID="33">
<IncidentConfig>
<AccountID>DDDDD</AccountID>
</IncidentConfig>
<cals>
<cal name="TC" value="26.0">
</cal>
<cal name="D" value="86.83612">
</cal>
</cals>
</Incident>
<Incident name="Subway3" active="true" primary="false" ActivityID="33">
<IncidentConfig>
<AccountID>DDDDD</AccountID>
</IncidentConfig>
<cals>
<cal name="PMP" value="39.0">
</cal>
<cal name="D" value="24.83612">
</cal>
</cals>
</Incident>
</Incidents>
</Quote>
</Response>
我知道在 XSLT for-each 循环中 break 是不可能的。但从以下示例中,如果我想显示名为 PMP 的“cal”元素存在,则取 PMP 值,如果不存在,取 TC 值。我尝试了下面的代码,但是没有用。
<charge>
<xsl:value-of select='/Response/Quote/Incidents/Incident/cals/cal[@name = "PMP"]'/>
</charge>
预期的 XML:
<Incident>
<charge>32.0</charge>
</Incident>
<Incident>
<charge>26.0</charge>
</Incident>
<Incident>
<charge>39.0</charge>
</Incident>
任何帮助表示赞赏。