2

我有来自 web 服务的这个 xml 输出:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <FLNewIndividualID xmlns="http://www.test.com/wsdl/TTypes">
       <ObjectType>C1</ObjectType>
       <ObjectReference>101000216193</ObjectReference>
       <ObjectReference xsi:nil="true"/>
       <ObjectReference xsi:nil="true"/>
    </FLNewIndividualID>
  </soapenv:Body>
</soapenv:Envelope>

我正在尝试提取 ObjectType 和 ObjectReference 所以我有这个 XSLT

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:nsl="http://www.test.com/wsdl/TTypes"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/env:Envelope/env:Body/nsl:FLNewIndividualID">
<xsl:value-of select="ObjectType"/>-<xsl:value-of select="ObjectReference"/>
</xsl:template>
</xsl:stylesheet>

我只是得到

<?xml version="1.0" encoding="utf-8"?>

结果如果我在结果中添加一个空白属性 xmlns="" 例如。

<ObjectType xmlns="">C1</ObjectType>
<ObjectReference xmlns="">101000216193</ObjectReference>

然后它起作用了,我得到:

<?xml version="1.0" encoding="utf-8"?>

  C1-101000216193

有任何想法吗?我无法更改 XML 输出。

4

1 回答 1

1

<FLNewIndividualID>一个默认命名空间集,因此它的子级继承该命名空间。

尝试

<xsl:value-of select="nsl:ObjectType" />
<xsl:text>-</xsl:text>
<xsl:value-of select="nsl:ObjectReference" />

使用exclude-result-prefixes.

例如像这样:

<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:nsl="http://www.test.com/wsdl/TTypes"
  exclude-result-prefixes="env nsl"
>
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="nsl:FLNewIndividualID">
    <xsl:value-of select="concat(nsl:ObjectType, '-', nsl:ObjectReference)" />
  </xsl:template>

  <xsl:template match="text()" />
</xsl:stylesheet>

(当然这个示例不会产生格式良好的 XML)

于 2013-11-13T10:56:51.983 回答