从xsl读取值

时间:2017-03-17 09:02:40

标签: xslt

我有一个xml,如:

 <UserData>
      <UserDataField name="IsShipAllow">true</UserDataField>
      <UserDataField name="OrderType">InHouse</UserDataField>
      <UserDataField name="OrderStockType">INSTOCK</UserDataField>
 </UserData>

我想在name =&#34; OrderStockType&#34;

时读取字段的值= INSTOCK

我已将xsl写为

<xsl:choose>
<xsl:when test="UserData/UserDataField/@name = 'OrderStockType'">
                            <xsl:attribute name="Type">
                                <xsl:value-of select="UserData/UserDataField/@name" />
                            </xsl:attribute>
                        </xsl:when>
                            <xsl:otherwise>
                            <xsl:attribute name="Type">FALSE</xsl:attribute>
                        </xsl:otherwise>
                    </xsl:choose>

1 个答案:

答案 0 :(得分:0)

为什么使用xsl从XML获取值? XPath可以更轻松地完成任务。试试/UserData/UserDataField[@name='OrderStockType']