XML : How do I get values from a diffrent document in XSLT

I need to merge two XML files via XSLT Version 1.0 . My Problem here is, that I need to add the Attributes of the 2nd XML-file to the Attributes of the first file. Let me give you an example to clarify my Problem.

XML1:

  <sample>    <tag a="1" b="2" c="3" d="4" />    <tag a="2" b="3" c="4" d="5" />  </sample>    

XML2:

  <sample>    <tag e="5" f="6" g="7" />    <tag e="10" f="12" g="11" />  </sample>    

Output:

  <sample>  <tag a="1" b="2" c="3" d="4" e="5" f="6" g="7" />  <tag a="2" b="3" c="4" d="5" e="10" f="12" g="11" />  </sample>    

I tried following XSLT for this:

  <?xml version="1.0" encoding="UTF-8"?>  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ws="http://www.w3schools.com">  <xsl:template match="/">                   <xsl:for-each select="sample/tag">  <tag>      <xsl:attribute name="a"><xsl:value-of select="@a"/></xsl:attribute>      <xsl:attribute name="b"><xsl:value-of select="@b"/></xsl:attribute>      <xsl:attribute name="c"><xsl:value-of select="@c"/></xsl:attribute>      <xsl:attribute name="d"><xsl:value-of select="@d"/></xsl:attribute>      <xsl:attribute name="e"><xsl:value-of select="document('xml2.xml')//@e"/></xsl:attribute>      <xsl:attribute name="f"><xsl:value-of select="document('xml2.xml')//@f"/></xsl:attribute>      <xsl:attribute name="g"><xsl:value-of select="document('xml2.xml')//@g"/></xsl:attribute>  <tag>  </xsl:for-each>     </xbrl>   </xsl:template>   </xsl:stylesheet>    

But I got only the first line of the 2nd XML-File. EG my Output was:

  <sample>  <tag a="1" b="2" c="3" d="4" e="5" f="6" g="7" />  <tag a="2" b="3" c="4" d="5" e="5" f="6" g="7" />  </sample>    

Hopefully anyone can help me with this. I am completly new to XSLT.

No comments:

Post a Comment