为什么xsl:value在这里不起作用(XML名称空间)?
我有来自ASP.NET Web API的以下XML片段:为什么xsl:value在这里不起作用(XML名称空间)?,xml,xslt,xpath,xml-namespaces,Xml,Xslt,Xpath,Xml Namespaces,我有来自ASP.NET Web API的以下XML片段: <DrilldownModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MY.API.Models"> <AddressInfo xmlns:d2p1="http://schemas.datacontract.org/2004/07/MY.API.En
<DrilldownModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/MY.API.Models">
<AddressInfo xmlns:d2p1="http://schemas.datacontract.org/2004/07/MY.API.Entities.Drilldown">
<d2p1:AddressNumber>4213</d2p1:AddressNumber>
<d2p1:AddressUseType>RESIDENTIAL</d2p1:AddressUseType>
<d2p1:EncryptedParcelId i:nil="true" />
<d2p1:GisError i:nil="true" />
<d2p1:GisErrorDetail i:nil="true" />
</AddressInfo>
</DrilldownModel>
4213
住宅的
我使用以下方法尝试从文档中获取值:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/MY.API.Models"
xmlns:d2p1="http://schemas.datacontract.org/2004/07/MY.API.Entities.Drilldown"
>
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="//AddressInfo/d2p1:AddressNumber"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
然而,我没有得到的价值回来。如果删除,则默认名称空间xmlns=”http://schemas.datacontract.org/2004/07/MY.API.Models
,我可以检索该值
有什么想法吗?认识到默认名称空间也适用于没有名称空间前缀的子元素,并且在
xsl:stylesheet
上声明默认名称空间不会影响XSLT中的XPath
因此,在XSLT中,为默认名称空间定义名称空间前缀:
xmlns:i="http://schemas.datacontract.org/2004/07/MY.API.Models"
然后更换
<xsl:value-of select="//AddressInfo/d2p1:AddressNumber"/>
与
这样您就可以在
http://schemas.datacontract.org/2004/07/MY.API.Models
它所在的名称空间。哦,天哪,这很简单!!像冠军一样工作。谢谢。
<xsl:value-of select="//m:AddressInfo/d2p1:AddressNumber"/>