Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSLT删除Soap环境&;将单个XSI标记复制到其自己的字段中_Xml_Xslt - Fatal编程技术网

Xml XSLT删除Soap环境&;将单个XSI标记复制到其自己的字段中

Xml XSLT删除Soap环境&;将单个XSI标记复制到其自己的字段中,xml,xslt,Xml,Xslt,我正在尝试从soap环境中复制XML,并且我已经成功地完成了这项工作。接下来,我想删除所有的xmln,这也是我能够成功完成的。但是,我现在尝试从XML负载的中间选择一个XSI属性,并在XML中创建一个新字段,其中包含XSI=TYPE字段的内容。我将展示我希望做的事情: 示例XML: <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/

我正在尝试从soap环境中复制XML,并且我已经成功地完成了这项工作。接下来,我想删除所有的xmln,这也是我能够成功完成的。但是,我现在尝试从XML负载的中间选择一个XSI属性,并在XML中创建一个新字段,其中包含XSI=TYPE字段的内容。我将展示我希望做的事情:

示例XML:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <notifications xmlns="http://soap.sforce.com/2005/09/outbound">
            <ActionId>04kf000000000FfAAI</ActionId>
            <SessionId xsi:nil="true"/>
            <Notification>
                <Id>04lf00000000xvQAAQ</Id>
                <sObject xsi:type="sf:Account" xmlns:sf="urn:sobject">
                    <sf:Id>001f0000006UzdCAAS</sf:Id>
                    <sf:Customer_Number__c>dummy1234</sf:Customer_Number__c>
                    <sf:FirstName>Test</sf:FirstName>
                    <sf:LastModifiedDate>2012-10-15T10:59:54.000Z</sf:LastModifiedDate>
                    <sf:LastName>Test</sf:LastName>
                </sObject>
            </Notification>
        </notifications>
    </soapenv:Body>
</soapenv:Envelope>

04kf000000000FfAAI
04LF00000000xVQAQ
001f0000006UzdCAAS
达米1234
试验
2012-10-15T10:59:54.000Z
试验
当前XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:r="http://soap.sforce.com/2005/09/outbound"
    exclude-result-prefixes="r">

    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <xsl:apply-templates select="/soap:Envelope//r:notifications"/>
    </xsl:template>

    <xsl:template match ="*" >
        <xsl:element name ="{local-name()}" >
            <xsl:apply-templates select ="@* | node()" />
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

输出:

<?xml version="1.0" encoding="utf-8"?>
<notifications>
   <ActionId>04kf000000000FfAAI</ActionId>
   <SessionId>true</SessionId>
   <Notification>
      <Id>04lf00000000xvQAAQ</Id>
      <sObject>tableName<Id>001f0000006UzdCAAS</Id>
         <Customer_Number__c>dummy1234</Customer_Number__c>
         <FirstName>Test</FirstName>
         <LastModifiedDate>2012-10-15T10:59:54.000Z</LastModifiedDate>
         <LastName>Test</LastName>
      </sObject>
   </Notification>
</notifications>

04kf000000000FfAAI
真的
04LF00000000xVQAQ
表名001F0000006UZDCAAS
达米1234
试验
2012-10-15T10:59:54.000Z
试验
这是不正确的,因为只是将XSI:TYPE的内容放在sObject中,我需要在它自己的字段中,例如,这是所需的输出:

<?xml version="1.0" encoding="utf-8"?>
<notifications>
   <ActionId>04kf000000000FfAAI</ActionId>
   <SessionId>true</SessionId>
   <Notification>
      <Id>04lf00000000xvQAAQ</Id>
      <sObject>
         <tableName>tableName</tableName>
         <Id>001f0000006UzdCAAS</Id>
         <Customer_Number__c>dummy1234</Customer_Number__c>
         <FirstName>Test</FirstName>
         <LastModifiedDate>2012-10-15T10:59:54.000Z</LastModifiedDate>
         <LastName>Test</LastName>
      </sObject>
   </Notification>
</notifications>

04kf000000000FfAAI
真的
04LF00000000xVQAQ
对应表名
001f0000006UzdCAAS
达米1234
试验
2012-10-15T10:59:54.000Z
试验

通过添加新模板对
sObject
进行自定义处理,您可以将属性手动处理到新元素中,然后继续处理

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:r="http://soap.sforce.com/2005/09/outbound"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    exclude-result-prefixes="r soap xsi">

    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/">
        <xsl:apply-templates select="/soap:Envelope//r:notifications"/>
    </xsl:template>

    <xsl:template match ="*" >
        <xsl:element name ="{local-name()}" >
            <xsl:apply-templates select ="@* | node()" />
        </xsl:element>
    </xsl:template>

    <xsl:template match="*[local-name()='sObject']">
        <sObject>
            <tableName>
                <xsl:value-of select="@xsi:type"/>
            </tableName>
            <xsl:apply-templates />
        </sObject>
    </xsl:template>

</xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?>
<notifications>
  <ActionId>04kf000000000FfAAI</ActionId>
  <SessionId>true</SessionId>
  <Notification>
    <Id>04lf00000000xvQAAQ</Id>
    <sObject>
      <tableName>sf:Account</tableName>
      <Id>001f0000006UzdCAAS</Id>
      <Customer_Number__c>dummy1234</Customer_Number__c>
      <FirstName>Test</FirstName>
      <LastModifiedDate>2012-10-15T10:59:54.000Z</LastModifiedDate>
      <LastName>Test</LastName>
    </sObject>
  </Notification>
</notifications>
<xsl:value-of select="@*[local-name()='type']"/>