【发布时间】:2017-05-18 17:53:27
【问题描述】:
我是 XSLT 的新手
我有一个输入 xml
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<urn:LookupRecords xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:a="urn:RedIron.RetailRepository.Core" xmlns:urn="urn:RedIron.RetailRepository.Services.SearchService">
<urn:query>
<a:Headers>
<a:SearchHeader>
<a:SearchHeader>
<a:SearchHeader>
</a:Headers>
<a:Params>
<arr:KeyValueOfguidArrayOfQueryParametertmL6yAXy>
</a:Params>
</urn:query>
</urn:LookupRecords>
</soapenv:Body>
</soapenv:Envelope>
输出的 XML 是
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetRecordResponse xmlns="urn:RedIron.RetailRepository.Services.SearchService">
<GetRecordResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="urn:RedIron.RetailRepository.Core">
<a:Exception i:nil="true"/>
<a:ResponseHeaders>
<a:SearchResults>
<a:StatusCode>Success</a:StatusCode>
<a:StatusCodeReason i:nil="true"/>
</GetRecordResult>
</GetRecordResponse>
</s:Body>
</s:Envelope>
现在我正在尝试使用 XSLT 更改转换,例如
<s:Envelope>
<xsl:attribute name="xmlns:s"><xsl:value-of select="xmlns:soapenv"/></xsl:attribute>
<s:Body>
</s:Body>
</s:Envelope>
但收到错误“格式不正确:元素“s:Envelope”的前缀“s”未绑定。”
你能帮忙吗
【问题讨论】:
-
xmlns不是属性。您不能使用<xsl:attribute>创建它们。您错过了有关 XML 名称空间的基本知识,应该花时间阅读它们。另外,请展示更多您当前的 XSLT。 -
这里有一些学习命名空间的资源:@987654321@ 和 jclark.com/xml/xmlns.htm
-
发布整个 XSLT 会很有用,因为您似乎缺乏有关它的基本知识。
-
用整个 XSLT 编辑。请告诉我是否有其他方法可以转换它。
-
这几乎不是“整个 XSLT”。请查看:minimal reproducible example.