Using XSLT to take data from two XML files and merge into one? -


i'm trying merge 2 tables using xslt 1.0.

i have representation of 2 db tables in xml. first table set of key-value pairs:

table1.xml

<table>   <row>     <column name="key">key1</column>     <column name="value">val1</column>   </row>   <row>     <column name="key">key2</column>     <column name="value">val2</column>   </row> </table> 

the second table has rows of data:

table2.xml

<table>   <row>     <column name="a">a1</column>     <column name="b">b1</column>     <column name="c">c1</column>   </row>   <row>     <column name="a">a2</column>     <column name="b">b2</column>     <column name="c">c2</column>   </row> </table> 

i trying take 1 of key-value pairs , add insert new column in every row ends this:

output.xml

<table>   <row>     <column name="a">a1</column>     <column name="b">b1</column>     <column name="c">c1</column>     <column name="key1">val1</column>   </row>   <row>     <column name="a">a2</column>     <column name="b">b2</column>     <column name="c">c2</column>     <column name="key1">val1</column>   </row> </table> 

i want select row key "key1" , create new column in output table.

assuming processing table2.xml file, can do:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <xsl:variable name="val" select="document('table1.xml')/table/row[column[1]='key1']/column[2]" />  <!-- identity transform --> <xsl:template match="@*|node()">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>     </xsl:copy> </xsl:template>  <xsl:template match="row">     <xsl:copy>         <xsl:apply-templates/>         <column name="key1">             <xsl:value-of select="$val" />         </column>     </xsl:copy> </xsl:template>  </xsl:stylesheet> 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -