通过 XSLT 将输入 XML 复制到输出

use*_*529 3 xml xslt

下面是我的输入xml

<ServiceIncident xmlns="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2">
    <RequesterID/>
    <ProviderID>INC0011731</ProviderID>
    <ProviderPriority>4</ProviderPriority>
    <WorkflowStatus>NEW</WorkflowStatus>
    <Transaction>
        <Acknowledge>1</Acknowledge>
        <StatusCode>0</StatusCode>
        <Comment>String</Comment>
        <TransactionName>Problem_Submittal</TransactionName>
        <TransactionType>2</TransactionType>
        <TransactionDateTime>2012-10-19T16:05:56Z</TransactionDateTime>
        <TransactionNumber>2012-10-19T16:05:56Z:1ae9b6a79901fc40fa75c64e1cdcc3b4</TransactionNumber>
        <TransactionRouting>MX::ITELLASNINCBRDG</TransactionRouting>
        <DataSource>ServiceNow</DataSource>
        <DataTarget>NASPGR72</DataTarget>
    </Transaction>
</ServiceIncident>
Run Code Online (Sandbox Code Playgroud)

我的要求是我需要将整个输入复制为输出,但输入中的一个字段需要在输出中更改。

下面是我在 xslt 中用于复制输入的代码。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:r2="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2">
    <xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>           
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

通过在 xslt 中使用上述代码,我可以将整个输入复制为输出,但根据我的要求,我需要映射 TransactionDateTime 而不是硬编码值

      <TransactionDateTime>2012-10-19T16:05:56Z</TransactionDateTime>
Run Code Online (Sandbox Code Playgroud)

我需要在事务中使用这个函数而不是硬编码。下面是我的 xslt 代码,但它没有给出输出

    <xsl:template match="r2:TransactionDateTime">
            <xsl:value-of select="current-dateTime()"/>
     </xsl:template>
Run Code Online (Sandbox Code Playgroud)

Lin*_* CS 5

添加与要更改的节点匹配的另一个模板,并在其中执行更改:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:r2="http://b2b.ibm.com/schema/IS_B2B_CDM/R2_2">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>           
    </xsl:copy>
</xsl:template>

<xsl:template match="r2:DataSource">
    <xsl:copy>Maximo</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)