2015-11-13 25 views
3

我正在從這樣卸下XML聲明(<?XML版本= 「1.0」 編碼= 「UTF-8」?>),使用XSLT 1.0內Cdata的

輸入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> 

回答

3

你可以嘗試這樣的事:

<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> 
+0

感謝您的幫助丹 –