)-6ren"> )-我从 SharePoint 应用程序中得到这样的响应 输入 <?xml version="1.0" encoding="UTF-8"?> -6ren">
gpt4 book ai didi

xml - 使用 Cdata 中的 XSLT 1.0 删除 xml 声明()

转载 作者:数据小太阳 更新时间:2023-10-29 02:29:19 24 4
gpt4 key购买 nike

我从 SharePoint 应用程序中得到这样的响应

输入

 <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response>&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
&lt;CopyIntoItemsResult>0&lt;/CopyIntoItemsResult>
&lt;Results>
&lt;CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/"/>
&lt;/Results>
&lt;/CopyIntoItemsResponse></Sharepoint_Response>
</SharepointResponse>
</Body>
</Envelope>

我正在使用这段代码

代码:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
<!--Identity template simply copies content forward -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="*" />
<xsl:value-of select="text()" disable-output-escaping="yes"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

给出输出:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response><?xml version="1.0" encoding="UTF-8"?>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/enterprise/"/>
</Results>
</CopyIntoItemsResponse></Sharepoint_Response>
</SharepointResponse>
</Body>
</Envelope>

我不确定如何删除这个 <?xml version="1.0" encoding="UTF-8"?><Sharepoint_Response> 之后

预期输出:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/enterprise/"/>
</Results>
</CopyIntoItemsResponse></Sharepoint_Response>
</SharepointResponse>
</Body>
</Envelope>

最佳答案

你可以尝试这样的事情:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
<!--Identity template simply copies content forward -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="*" />
<xsl:value-of select="substring-after(text(),'?&gt;')" disable-output-escaping="yes" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

想法是使用 substring-after 来获取关闭 ?> 部分 XML 声明之后的所有内容。使用该样式表得到以下输出:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<SharepointResponse xmlns="http://test.com.services.generic">
<Sharepoint_Response>
<CopyIntoItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<CopyIntoItemsResult>0</CopyIntoItemsResult>
<Results>
<CopyResult ErrorCode="Success" DestinationUrl="http://archivelink.dev.test.com/"/>
</Results>
</CopyIntoItemsResponse></Sharepoint_Response></SharepointResponse></Body></Envelope>

关于xml - 使用 Cdata 中的 XSLT 1.0 删除 xml 声明(<?xml 版本 ="1.0"编码 ="UTF-8"?>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33701352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com