在 Cdata 中使用 XSLT 1.0 删除 xml 声明(<?xml version=“1.0" encoding=“UTF-8"?>) [英] Removing xml declaration (<?xml version="1.0" encoding="UTF-8"?>) using XSLT 1.0 inside Cdata
本文介绍了在 Cdata 中使用 XSLT 1.0 删除 xml 声明(<?xml version=“1.0" encoding=“UTF-8"?>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 SharePoint 应用程序收到这样的响应
I am getting the response from the SharePoint application like this
输入
<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/"/>
</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="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"?>
预期输出:
<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(),'?>')" disable-output-escaping="yes" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这个想法是使用 substring-after
来获取 XML 声明的关闭 ?>
部分之后的所有内容.使用该样式表给了我以下输出:
The idea is to use substring-after
to get everything after that closing ?>
part of the XML declaration. Using that stylesheet gave me the following output:
<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>
这篇关于在 Cdata 中使用 XSLT 1.0 删除 xml 声明(<?xml version=“1.0" encoding=“UTF-8"?>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文