Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merging 2 xml's to 1 xml via xslt

Status
Not open for further replies.

progressdll

Programmer
Feb 28, 2002
41
BE
merging 2 xml's to 1 xml

xml 1 ( and my source xml )

<root>
<row>
<cell>
<data>1</data>
<namedcell name=&quot;linenr&quot;>
</cell>
<cell>
<data>100</data>
<namedcell name=&quot;article&quot;>
</cell>
</row>
</root>

xml that i import via the document function

<root>
<orderlines linenr=&quot;1&quot;>
<article>77</article>
<orderlines linenr=&quot;2&quot;>
<article>88</article>
<orderlines linenr=&quot;3&quot;>
<article>99</article>
</root>

Now i want to get the following output xml.
i want to use the namedcell attribute name to make the match.
so i can add more elements to the import xml.

I tried seve ral approached but now i am stuck.
I can't figure out how to get the elements from the import file
and match the to my source.

<root>
<row>
<cell>
<data>1</data>
<namedcell name=&quot;linenr&quot;>
</cell>
<cell>
<data>77</data>
<namedcell name=&quot;article&quot;>
</cell>
</row>
<row>
<cell>
<data>2</data>
<namedcell name=&quot;linenr&quot;>
</cell>
<cell>
<data>88</data>
<namedcell name=&quot;article&quot;>
</cell>
</row>
<row>
<cell>
<data>3</data>
<namedcell name=&quot;linenr&quot;>
</cell>
<cell>
<data>99</data>
<namedcell name=&quot;article&quot;>
</cell>
</row>
</root>
 
Hi,
first of all, your xml source & input do not parse. I assume in xml 1 <namedcell name=&quot;linenr&quot;> is an empty element(<namedcell name=&quot;linenr&quot;/>)and in xml 2 the element <orderlines> will be closed after the child element <article>.(<orderlines linenr=&quot;1&quot;><article>77</article></orderlines>
)
Did you try using variables to activate the xslt document function?

something like this in the starting template
<xsl:for-each select=&quot;//cell/&quot;>
<xsl:variable name=&quot;namedcell&quot; select=&quot;namedcell/@name&quot;/>

and in the include template

<xsl:for-each select=&quot;document('xml2.xml')/root/orderlines[@linenr=$namedcell]&quot;>
<cell><data>
<xsl:value-of select=&quot;@orderlines&quot;/>
</data></cell>
<cell><data>
<xsl:value-of select=&quot;/article&quot;/>
</data></cell>
</xsl:for-each>

Hope this helps.
- Vangelh



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top