Xml 如何在xslt映射中将子记录数据从源复制到目标
我有一个源xml,如下所示Xml 如何在xslt映射中将子记录数据从源复制到目标,xml,xslt,xslt-1.0,biztalk,Xml,Xslt,Xslt 1.0,Biztalk,我有一个源xml,如下所示 <customerSource> <Name>abc</Name> <Account>123</Account> <AccountInfoSource> <AccountLocaiton>Florida-MI</AccountLocaiton> <AccountZip>12341</AccountZip> <
<customerSource>
<Name>abc</Name>
<Account>123</Account>
<AccountInfoSource>
<AccountLocaiton>Florida-MI</AccountLocaiton>
<AccountZip>12341</AccountZip>
<AccountBank>BOA</AccountBank>
<AccountBalance>0.0001</AccountBalance>
<AccountStatus>Active</AccountStatus>
.
.
.
.
.
</AccountInfoSource>
<Employed>Yes</Employed>
</customerSource>
<ns0:customerDestination>
<ns0:Account>
<xsl:value-of select="ns0:customerDestination/ns0:Account" />
</ns0:Account>
<ns0:AccountInfoDestination>
<xsl:value-of select="ns0:customerDestination/ns0:AccountInfoSource/text()" />
</ns0:AccountInfoDestination>
<ns0:Employed>
<xsl:value-of select="ns0:customerDestination/ns0:Employed" />
</ns0:Employed>
</ns0:customerDestination>
abc
123
佛罗里达密苏里州
12341
博阿
0.0001
活跃的
.
.
.
.
.
对
我可以在AccountInfoSource中使用任何元素。所以,我必须将AccountInfoSource记录数据复制到AccountInfoDestination,您能帮忙吗
我试着如下
<customerSource>
<Name>abc</Name>
<Account>123</Account>
<AccountInfoSource>
<AccountLocaiton>Florida-MI</AccountLocaiton>
<AccountZip>12341</AccountZip>
<AccountBank>BOA</AccountBank>
<AccountBalance>0.0001</AccountBalance>
<AccountStatus>Active</AccountStatus>
.
.
.
.
.
</AccountInfoSource>
<Employed>Yes</Employed>
</customerSource>
<ns0:customerDestination>
<ns0:Account>
<xsl:value-of select="ns0:customerDestination/ns0:Account" />
</ns0:Account>
<ns0:AccountInfoDestination>
<xsl:value-of select="ns0:customerDestination/ns0:AccountInfoSource/text()" />
</ns0:AccountInfoDestination>
<ns0:Employed>
<xsl:value-of select="ns0:customerDestination/ns0:Employed" />
</ns0:Employed>
</ns0:customerDestination>
输出应该如下所示
<ns0:customerDestination>
<ns0:Account>123</ns0:Account>
<ns0:AccountInfoDestination>
<ns0:AccountLocaiton>Florida-MI</ns0:AccountLocaiton>
<ns0:AccountZip>12341</ns0:AccountZip>
<ns0:AccountBank>BOA</ns0:AccountBank>
<ns0:AccountBalance>0.0001</ns0:AccountBalance>
<ns0:AccountStatus>Active</ns0:AccountStatus>
.
.
.
.
.
</ns0:AccountInfoDestination>
<ns0:Employed>Yes</ns0:Employed>
</ns0:customerDestination>
123
佛罗里达密苏里州
12341
博阿
0.0001
活跃的
.
.
.
.
.
对
您同时使用xslt-1.0
和xslt-2.0
为问题添加了标签,这毫无意义,因为这些标签意味着相互排斥。下面的解决方案适用于两个版本的XSLT,因为XSLT2.0处理器也可以处理XSLT1.0文档
最重要的模板:
<xsl:template match="AccountInfoSource/* | Account | Employed">
然后将这些元素的文本内容原封不动地复制到输出树
样式表
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="http://www.namespace.com">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:template match="/customerSource">
<ns0:customerDestination>
<xsl:apply-templates/>
</ns0:customerDestination>
</xsl:template>
<xsl:template match="Name"/>
<xsl:template match="AccountInfoSource">
<ns0:AccountInfoDestination>
<xsl:apply-templates/>
</ns0:AccountInfoDestination>
</xsl:template>
<xsl:template match="AccountInfoSource/* | Account | Employed">
<xsl:element name="{concat('ns0:',local-name())}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:transform>
您已经用xslt-1.0和xslt-2.0标记了您的问题-您实际需要哪一个?请尝试使用xsl:copy of。。