使用 XSLT 复制节点和子节点 [英] Copy Nodes and Children Using XSLT

查看:29
本文介绍了使用 XSLT 复制节点和子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This seems like a pretty basic XSLT question, but I have not been able to find the answer.

我的 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 下的所有元素.

I would like to copy all nodes under ProcessData/Document. Currently, this only copies the values. I would like to copy all the elements under 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>

有没有办法做到这一点?

Is there a way to do that?

谢谢.

推荐答案

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

If you are sure that's the output you want, you can achieve it very easily by:

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>

这篇关于使用 XSLT 复制节点和子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆