This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re:Re: Joining two XML-files


Hi,  Jeni,
I try to work out suggestions for joining two XML-files  to Jorge,
> These files are related through the commom value of an attribute. In
> the previous example file1.att1 is found in file2.fld1 I need to
> produce a third file where get mixed some attributes of the related
> "records".For example:
>
> file3.xml
>     <row att1='foo' att2='morefoo" fld2='otherfoo" />
>     <row att1='foo2' att2='morefoo2" fld2='otherfoo2" />
>     <row att1='foo2' att2='morefoo2" fld2='anotherfoo2" />
> ...
> </data>

However, I  got files3 with two rows ,  do I misinterpret your suggestions?

**   file3.xml
<data>
<row att1="foo" att2="morefoo" fld2="otherfoo">
</row>
<row att1="foo2" att2="morefoo2" fld2="anotherfoo2">
</row>
</data>

**  xsl file **
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

 <xsl:output method="xml" indent="yes" />
 <xsl:key name="rows-by-fld1" match="row" use="@fld1" />

<xsl:variable name="file1" select="document('file1.xml')" />
<xsl:variable name="file2" select="document('file2.xml')" />
<xsl:template match="/">
<data>
<xsl:for-each select="$file1/data/row">
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:variable name="att1" select="@att1" />
<xsl:for-each select="$file2">
   <xsl:copy-of select="key('rows-by-fld1', $att1)/@*[name()!='fld1']" />
</xsl:for-each>
    </xsl:copy>
  </xsl:for-each>
  </data>
  </xsl:template>

</xsl:stylesheet>

Sun-fu Yang

sfyang@unisvr.net.tw



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]