Xml 使用XSL将两个文件中的数据合并为一个文件

Xml 使用XSL将两个文件中的数据合并为一个文件,xml,xslt,xslt-1.0,merging-data,Xml,Xslt,Xslt 1.0,Merging Data,我有两个XML文件,我正在尝试使用xsl合并一些元素 <xsl:template match="/"> <GroupList> <Group> <xsl:apply-templates/> </Group> </GroupList> </xsl:template> <xsl:template match="a:BusinessUnit"> <xsl:variable name="busin

我有两个XML文件,我正在尝试使用xsl合并一些元素

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>
XML1:

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>
我想从第一个文件读取业务单元数据,从第二个文件读取产品系列数据,并生成组信息

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>
步骤如下: 阅读所有业务单元

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>
组名是:businessUnitCode和:longName的串联,我做了这部分

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>
当a:parentBusinessUnitCode为空时,读取其a:businessUnitCode,在第二个文件中搜索此businessUnitCode

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>
如果:businessunitcode第1个文件等于aa:parentBusinessUnitCode第2个文件 然后打印它的集成id

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>

请帮助我,因为我是xsl新手。

我在第二个XML中搜索了业务单位代码,并显示了相应的数据。注意,我使用document函数读取第二个XML。
<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>

<xsl:template match="/">
<GroupList>
 <Group>
 <xsl:apply-templates/>
</Group>
</GroupList>
</xsl:template>
<xsl:template match="a:BusinessUnit">
 <xsl:variable name="businessCode" select="a:businessUnitCode"/>
 <Name>
 <xsl:value-of select="$businessCode"/> - <xsl:value-of select="a:longName"/>
 </Name>
  <xsl:if test="a:parentBusinessUnitCode[@i:nil='true']">
  <ProductLineList>
  <xsl:for-each select=
  "document('XML2.xml')/Get_ProductFamily/aa:ProductFamily">
  <xsl:if test="aa:parentBusinessUnitCode = $businessCode">
  <ProductLine>
   <Name><xsl:value-of select="$businessCode"/></Name>

   <CODE><xsl:value-of select="aa:integrationId"/></CODE>
   </ProductLine></xsl:if>
 </xsl:for-each>
 </ProductLineList>
  </xsl:if>
 </xsl:template>
 </xsl:stylesheet>

您至少可以自己尝试一下。我已经为第一个文件及其工作状态使用了每个foreach,但无法在第二个文件上应用foreach。注意:您似乎错过了输入中的一些命名空间声明。你也应该向我们展示你的尝试。