EDN Admin
Well-known member
Two XML documents, the first primary input document being
First Document <br/>
<pre class="prettyprint <span class="tag <catalog><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Empire Burlesque<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bob Dylan<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Columbia<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1985<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Hide your heart<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bonnie Tyler<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS Records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1988<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Greatest Hits<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dolly Parton<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln RCA<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1982<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Still got the blues<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Gary Moore<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Virgin records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.20<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Eros<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Eros Ramazzotti<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln BMG<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1997<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln One night only<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bee Gees<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1998<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Sylvias Mother<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dr.Hook<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.10<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1973<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 4<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Maggie May<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Rod Stewart<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Pickwick<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.50<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Romanza<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Andrea Bocelli<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.80<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1996<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/><span class="tag </catalog><span class="pln [/code]
the second document mapping the old ids to new ones as in
Second Document <br/>
<pre class="prettyprint <span class="tag <catalog><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1001<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1002<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1003<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 4<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1004<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1001<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1002<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1003<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 4<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1005<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln C<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln C-1005<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/><span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln D<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln D-1005<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag </catalog>[/code]
and as the output you simply want to copy the first input but replace the id values then the following stylesheet shows
<pre class="prettyprint <span class="tag <xsl:stylesheet<span class="pln <br/> <span class="atn xmlns:xsl<span class="pun =<span class="atv "http://www.w3.org/1999/XSL/Transform"<span class="pln <br/> <span class="atn version<span class="pun =<span class="atv "1.0"<span class="tag ><span class="pln <br/> <br/> <span class="tag <xslaram<span class="pln <span class="atn name<span class="pun =<span class="atv "id-url"<span class="pln <span class="atn select<span class="pun =<span class="atv "idmap.xml"<span class="tag /><span class="pln <br/> <span class="tag <xsl:variable<span class="pln <span class="atn name<span class="pun =<span class="atv "id-doc"<span class="pln <span class="atn select<span class="pun =<span class="atv "document($id-url)"<span class="tag /><span class="pln <br/> <br/> <span class="tag <xsl:key<span class="pln <span class="atn name<span class="pun =<span class="atv "k1"<span class="pln <span class="atn match<span class="pun =<span class="atv "catalog/ids"<span class="pln <span class="atn use<span class="pun =<span class="atv "concat(package, |, id)"<span class="tag /><span class="pln <br/> <br/> <span class="tag <xsl:template<span class="pln <span class="atn match<span class="pun =<span class="atv "@* | node()"<span class="tag ><span class="pln <br/> <span class="tag <xsl:copy><span class="pln <br/> <span class="tag <xsl:apply-templates<span class="pln <span class="atn select<span class="pun =<span class="atv "@* | node()"<span class="tag /><span class="pln <br/> <span class="tag </xsl:copy><span class="pln <br/> <span class="tag </xsl:template><span class="pln <br/> <br/> <span class="tag <xsl:template<span class="pln <span class="atn match<span class="pun =<span class="atv "cd/id"<span class="tag ><span class="pln <br/> <span class="tag <xsl:copy><span class="pln <br/> <span class="tag <xsl:variable<span class="pln <span class="atn name<span class="pun =<span class="atv "this"<span class="pln <span class="atn select<span class="pun =<span class="atv "."<span class="tag /><span class="pln <br/> <span class="tag <xsl:for-each<span class="pln <span class="atn select<span class="pun =<span class="atv "$id-doc"<span class="tag ><span class="pln <br/> <span class="tag <xsl:value-of<span class="pln <span class="atn select<span class="pun =<span class="atv "key(k1, concat($this/parent::cd/package, |, $this))/newId"<span class="tag /><span class="pln <br/> <span class="tag </xsl:for-each><span class="pln <br/> <span class="tag </xsl:copy><span class="pln <br/> <span class="tag </xsl:template><span class="pln <br/> <br/><span class="tag </xsl:stylesheet>[/code]
The output is
<pre class="prettyprint <span class="tag <catalog><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1001<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Empire Burlesque<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bob Dylan<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Columbia<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1985<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1001<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Hide your heart<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bonnie Tyler<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS Records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1988<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln B-1001<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Greatest Hits<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dolly Parton<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln RCA<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1982<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln B-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Still got the blues<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Gary Moore<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Virgin records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.20<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln B-1003<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Eros<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Eros Ramazzotti<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln BMG<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1997<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln One night only<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bee Gees<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1998<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1003<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Sylvias Mother<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dr.Hook<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.10<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1973<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1004<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Maggie May<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Rod Stewart<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Pickwick<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.50<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Romanza<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Andrea Bocelli<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.80<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1996<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/><span class="tag </catalog>[/code]
----------------------------------------------------------------------------------------------------------------
The above codes are working fine
But i need to make a new filter in the above xsl
1. In the 2nd document there is package "C" and "D". Wht i need is . if 2nd document package is not exist in the 1st document create a node in the output like below with <Newid> as <id>
<pre class="prettyprint <span class="pln <span class="tag <catalog><span class="pln <br/>-<br/>-<br/>-<br/>-<span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Romanza<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Andrea Bocelli<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.80<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1996<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln C<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln C-1005<span class="tag </id><span class="pln <br/><span class="tag </cd><span class="pln <br/><span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln D<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln D-1005<span class="tag </id><span class="pln <br/><span class="tag </cd><span class="pln <br/> <span class="tag </catalog><span class="pln <br/>[/code]
View the full article
First Document <br/>
<pre class="prettyprint <span class="tag <catalog><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Empire Burlesque<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bob Dylan<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Columbia<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1985<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Hide your heart<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bonnie Tyler<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS Records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1988<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Greatest Hits<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dolly Parton<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln RCA<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1982<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Still got the blues<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Gary Moore<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Virgin records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.20<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Eros<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Eros Ramazzotti<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln BMG<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1997<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln One night only<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bee Gees<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1998<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Sylvias Mother<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dr.Hook<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.10<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1973<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 4<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Maggie May<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Rod Stewart<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Pickwick<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.50<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Romanza<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Andrea Bocelli<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.80<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1996<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/><span class="tag </catalog><span class="pln [/code]
the second document mapping the old ids to new ones as in
Second Document <br/>
<pre class="prettyprint <span class="tag <catalog><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1001<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1002<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1003<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 4<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln A-1004<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1001<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1002<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 3<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1003<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 4<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln B-1005<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln C<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 1<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln C-1005<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/><span class="tag <ids><span class="pln <br/> <span class="tag <package><span class="pln D<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln 2<span class="tag </id><span class="pln <br/> <span class="tag <newId><span class="pln D-1005<span class="tag </newId><span class="pln <br/> <span class="tag </ids><span class="pln <br/> <span class="tag </catalog>[/code]
and as the output you simply want to copy the first input but replace the id values then the following stylesheet shows
<pre class="prettyprint <span class="tag <xsl:stylesheet<span class="pln <br/> <span class="atn xmlns:xsl<span class="pun =<span class="atv "http://www.w3.org/1999/XSL/Transform"<span class="pln <br/> <span class="atn version<span class="pun =<span class="atv "1.0"<span class="tag ><span class="pln <br/> <br/> <span class="tag <xslaram<span class="pln <span class="atn name<span class="pun =<span class="atv "id-url"<span class="pln <span class="atn select<span class="pun =<span class="atv "idmap.xml"<span class="tag /><span class="pln <br/> <span class="tag <xsl:variable<span class="pln <span class="atn name<span class="pun =<span class="atv "id-doc"<span class="pln <span class="atn select<span class="pun =<span class="atv "document($id-url)"<span class="tag /><span class="pln <br/> <br/> <span class="tag <xsl:key<span class="pln <span class="atn name<span class="pun =<span class="atv "k1"<span class="pln <span class="atn match<span class="pun =<span class="atv "catalog/ids"<span class="pln <span class="atn use<span class="pun =<span class="atv "concat(package, |, id)"<span class="tag /><span class="pln <br/> <br/> <span class="tag <xsl:template<span class="pln <span class="atn match<span class="pun =<span class="atv "@* | node()"<span class="tag ><span class="pln <br/> <span class="tag <xsl:copy><span class="pln <br/> <span class="tag <xsl:apply-templates<span class="pln <span class="atn select<span class="pun =<span class="atv "@* | node()"<span class="tag /><span class="pln <br/> <span class="tag </xsl:copy><span class="pln <br/> <span class="tag </xsl:template><span class="pln <br/> <br/> <span class="tag <xsl:template<span class="pln <span class="atn match<span class="pun =<span class="atv "cd/id"<span class="tag ><span class="pln <br/> <span class="tag <xsl:copy><span class="pln <br/> <span class="tag <xsl:variable<span class="pln <span class="atn name<span class="pun =<span class="atv "this"<span class="pln <span class="atn select<span class="pun =<span class="atv "."<span class="tag /><span class="pln <br/> <span class="tag <xsl:for-each<span class="pln <span class="atn select<span class="pun =<span class="atv "$id-doc"<span class="tag ><span class="pln <br/> <span class="tag <xsl:value-of<span class="pln <span class="atn select<span class="pun =<span class="atv "key(k1, concat($this/parent::cd/package, |, $this))/newId"<span class="tag /><span class="pln <br/> <span class="tag </xsl:for-each><span class="pln <br/> <span class="tag </xsl:copy><span class="pln <br/> <span class="tag </xsl:template><span class="pln <br/> <br/><span class="tag </xsl:stylesheet>[/code]
The output is
<pre class="prettyprint <span class="tag <catalog><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1001<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Empire Burlesque<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bob Dylan<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Columbia<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1985<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1001<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Hide your heart<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bonnie Tyler<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS Records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1988<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln B-1001<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Greatest Hits<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dolly Parton<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln USA<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln RCA<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1982<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln B-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Still got the blues<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Gary Moore<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Virgin records<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.20<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln B<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln B-1003<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Eros<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Eros Ramazzotti<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln BMG<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 9.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1997<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln One night only<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Bee Gees<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.90<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1998<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1003<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Sylvias Mother<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Dr.Hook<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln CBS<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.10<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1973<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1004<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Maggie May<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Rod Stewart<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln UK<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Pickwick<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 8.50<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1990<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Romanza<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Andrea Bocelli<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.80<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1996<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/><span class="tag </catalog>[/code]
----------------------------------------------------------------------------------------------------------------
The above codes are working fine
But i need to make a new filter in the above xsl
1. In the 2nd document there is package "C" and "D". Wht i need is . if 2nd document package is not exist in the 1st document create a node in the output like below with <Newid> as <id>
<pre class="prettyprint <span class="pln <span class="tag <catalog><span class="pln <br/>-<br/>-<br/>-<br/>-<span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln A<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln A-1002<span class="tag </id><span class="pln <br/> <span class="tag <title><span class="pln Romanza<span class="tag </title><span class="pln <br/> <span class="tag <artist><span class="pln Andrea Bocelli<span class="tag </artist><span class="pln <br/> <span class="tag <country><span class="pln EU<span class="tag </country><span class="pln <br/> <span class="tag <company><span class="pln Polydor<span class="tag </company><span class="pln <br/> <span class="tag <price><span class="pln 10.80<span class="tag </price><span class="pln <br/> <span class="tag <year><span class="pln 1996<span class="tag </year><span class="pln <br/> <span class="tag </cd><span class="pln <br/> <span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln C<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln C-1005<span class="tag </id><span class="pln <br/><span class="tag </cd><span class="pln <br/><span class="tag <cd><span class="pln <br/> <span class="tag <package><span class="pln D<span class="tag </package><span class="pln <br/> <span class="tag <id><span class="pln D-1005<span class="tag </id><span class="pln <br/><span class="tag </cd><span class="pln <br/> <span class="tag </catalog><span class="pln <br/>[/code]
View the full article