gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:23:32 25 4
gpt4 key购买 nike

下面是我输入的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>

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

下面是我在 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>

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

      <TransactionDateTime>2012-10-19T16:05:56Z</TransactionDateTime>

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

    <xsl:template match="r2:TransactionDateTime">
<xsl:value-of select="current-dateTime()"/>
</xsl:template>

最佳答案

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

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

关于xml - 通过 XSLT 将输入 XML 复制到输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21707501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com