【问题标题】:Not getting any results back from this xslt没有从这个 xslt 得到任何结果
【发布时间】:2013-11-25 22:30:13
【问题描述】:

我有这个来自 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 输出。

【问题讨论】:

    标签: xml xslt transformation xml-namespaces


    【解决方案1】:

    &lt;FLNewIndividualID&gt; 有一个默认命名空间集,因此它的子级会继承该命名空间。

    试试

    <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-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      相关资源
      最近更新 更多