我不能 select 来自命名空间 XML 的节点值并且没有得到任何值
I can't select a node value from a namespaced XML and getting no value
我在尝试获取位于命名空间 XML 内的 "streetNumber" 的节点值时遇到问题。下面是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:tns="http://xsd.hometrack.com.au/pih/" xmlns:vms="http://www.sandstone-vms.com.au/schema/vms/1.0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xs="http://wsdl.hometrack.com.au/pih/">
<soap:Body>
<xs:getPropertyResponse xmlns="http://wsdl.hometrack.com.au/pih/" xmlns:xs="http://wsdl.hometrack.com.au/pih/">
<pih xmlns="http://xsd.hometrack.com.au/pih/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<propertyResponse>
<property>
<address>
<streetNumber>32</streetNumber>
<streetName>SPARKLE</streetName>
</address>
</property>
</propertyResponse>
</pih>
</xs:getPropertyResponse>
</soap:Body>
</soap:Envelope>
我的 XSLT 是:
<xsl:template match="/soapenv:Envelope/soapenv:Body">
<xsl:element name="response">
<xsl:element name="output">
<xsl:attribute name="streetNumber"><xsl:value-of select="xs:getPropertyResponse/pih/propertyResponse/property/address/streetNumber" /></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
下面是我没有得到 "StreetNumber"
值的结果
<?xml version="1.0" encoding="UTF-8"?>
<response><output streetNumber=""/>
</response>
这方面的任何帮助都会对我有所帮助。非常感谢!
在 XSLT 中,需要定义那些名称空间,这些名称空间位于 XML.
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xs="http://wsdl.hometrack.com.au/pih/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="soap:Envelope/soap:Body">
<xsl:element name="response">
<xsl:element name="output">
<xsl:attribute name="streetNumber"><xsl:value-of select="xs:getPropertyResponse/*:pih/*:propertyResponse/*:property/*:address/*:streetNumber" /></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
结果:
<response><output streetNumber="32"/></response>
我在尝试获取位于命名空间 XML 内的 "streetNumber" 的节点值时遇到问题。下面是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:tns="http://xsd.hometrack.com.au/pih/" xmlns:vms="http://www.sandstone-vms.com.au/schema/vms/1.0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xs="http://wsdl.hometrack.com.au/pih/">
<soap:Body>
<xs:getPropertyResponse xmlns="http://wsdl.hometrack.com.au/pih/" xmlns:xs="http://wsdl.hometrack.com.au/pih/">
<pih xmlns="http://xsd.hometrack.com.au/pih/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<propertyResponse>
<property>
<address>
<streetNumber>32</streetNumber>
<streetName>SPARKLE</streetName>
</address>
</property>
</propertyResponse>
</pih>
</xs:getPropertyResponse>
</soap:Body>
</soap:Envelope>
我的 XSLT 是:
<xsl:template match="/soapenv:Envelope/soapenv:Body">
<xsl:element name="response">
<xsl:element name="output">
<xsl:attribute name="streetNumber"><xsl:value-of select="xs:getPropertyResponse/pih/propertyResponse/property/address/streetNumber" /></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
下面是我没有得到 "StreetNumber"
值的结果<?xml version="1.0" encoding="UTF-8"?>
<response><output streetNumber=""/>
</response>
这方面的任何帮助都会对我有所帮助。非常感谢!
在 XSLT 中,需要定义那些名称空间,这些名称空间位于 XML.
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xs="http://wsdl.hometrack.com.au/pih/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="soap:Envelope/soap:Body">
<xsl:element name="response">
<xsl:element name="output">
<xsl:attribute name="streetNumber"><xsl:value-of select="xs:getPropertyResponse/*:pih/*:propertyResponse/*:property/*:address/*:streetNumber" /></xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
结果:
<response><output streetNumber="32"/></response>