.net 将一个XML转换为另一个XML

.net 将一个XML转换为另一个XML,.net,xml,xslt,.net,Xml,Xslt,我对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" xml

我对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”


您能在这方面提供帮助吗正如前面提到的,名称空间声明不是属性,不能使用
xsl:attribute
指令创建。为了编写XSLT代码段中显示的文本结果元素,您需要更改以下代码:

<s:Envelope>
<xsl:attribute name="xmlns:s"><xsl:value-of select="xmlns:soapenv"/></xsl:attribute>
<s:Body>
</s:Body>
</s:Envelope> 

致:



请注意,该声明适用于包含它的节点的所有后代(因此无需对
s:Body
元素重复该声明)。通常,您会将所有名称空间声明包含在顶级
xsl:stylesheet
标记中。

xmlns
不是属性。不能使用
创建它们。您缺少关于XML名称空间的基本知识,应该花时间阅读它们。另外,请展示更多您当前的XSLT。以下是一些用于学习名称空间的资源:发布您的整个XSLT将非常有用,因为您似乎缺乏关于它的基本知识。使用整个XSLT编辑。。请让我知道是否有其他方法可以进行转换。这几乎不是“整个XSLT”。请查看:.Hi@michael.hor257k谢谢您的回复。我已经重新设计了这个问题。你能帮我一下吗。
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
</s:Body>
</s:Envelope>