使用 XSLT 复制节点和子节点

2024-04-02

这似乎是一个非常基本的 XSLT 问题,但我一直无法找到答案。

我的 XSLT 是:

<xsl:template match="ProcessData/Document" >
    <xsl:element name="urn:create">
   <urn:sObjects xsi:type="urn1:O2C_Alert__c">
    <xsl:copy>
    <xsl:apply-templates select="ProcessData/Document" />
   </xsl:copy>
</urn:sObjects>

我想复制 ProcessData/Document 下的所有节点。目前,这仅复制值。我想复制 ProcessData/Document 下的所有元素。

<ProcessData>
  <Document>
    <OTC_Alerts_KNA>
<Header><current_date_time_of_application_server>2015-03-31T21:56:51</current_date_time_of_application_server>
        <alert_type>EDI</alert_type>
        <single_character_indicator>O</single_character_indicator>
        <alert_functional_area>ORD</alert_functional_area>
        <customer_number>1000000131</customer_number>
        <customer_name>Dot Foods</customer_name>
        <sales_document_number>0000012062</sales_document_number>
        <sales_document_type>ZOR</sales_document_type>
    </Header>
    </OTC_Alerts_KNA>
  </Document>
</ProcessData>

我试图最终得到这个:

<?xml version="1.0" encoding="UTF-8"?>
<urn:create
    xmlns:urn="urn:enterprise.soap.sforce.com">
    <urn:sObjects
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xsi:type="urn1:O2C_Alert__c"/>
                <OTC_Alerts_KNA>
    <Header><current_date_time_of_application_server>2015-03-31T21:56:51</current_date_time_of_application_server>
            <alert_type>EDI</alert_type>
            <single_character_indicator>O</single_character_indicator>
            <alert_functional_area>ORD</alert_functional_area>
            <customer_number>1000000131</customer_number>
            <customer_name>Dot Foods</customer_name>
            <sales_document_number>0000012062</sales_document_number>
            <sales_document_type>ZOR</sales_document_type>
        </Header>
        </OTC_Alerts_KNA>
    </urn:create>

有没有办法做到这一点?

Thanks.


如果您确定这就是您想要的输出,您可以通过以下方式轻松实现:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
    <urn:create xmlns:urn="urn:enterprise.soap.sforce.com">
        <urn:sObjects xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xsi:type="urn1:O2C_Alert__c"/>
        <xsl:copy-of select="ProcessData/Document/*"/>
    </urn:create>
</xsl:template>

</xsl:stylesheet>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 XSLT 复制节点和子节点 的相关文章

随机推荐