This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > September 2004 > combining two xml docs into one document?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author combining two xml docs into one document?
Tarren

2004-09-21, 7:16 pm

Hi:

Here is the challenge I am faced with.

I have two XML strings

This one comes from Personnel
<employeedata>
<employeeID>1234</employeeID>
<employeename>John Smith</employeename>
<employeelocation>US</employeelocation>
</employeedata>

This one comes from HR
<employeedata>
<employeeID>1234</employeeID>
<salary>40000</salary>
<payzone>4</payzone>
</employeedata>

The result I need is this
<employeedata>
<employeeID>1234</employeeID>
<employeename>John Smith</employeename>
<employeelocation>US</employeelocation>
<salary>40000</salary>
<payzone>4</payzone>
</employeedata>

The books I have do not deal with this kind of scenario.

Is this easier to do with XSLT Stylesheet or programmatically (I am using VB
..NET). Has anyone dealt with or have any example code of either an XSLT
approach or using an XMLDocument in VB .NET.

Thanks for your help!


Jonathan Chong

2004-09-22, 11:21 am

You can try this:

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

<xsl:param name="xml2" select="document('hr.xml')"/>

<xsl:template match="/">
<table>
<xsl:apply-templates select="/" mode="personneldata"/>
</table>
</xsl:template>

<xsl:template match="employeedata" mode="personneldata">
<xsl:choose>
<xsl:when test="employeeID = $xml2/employeedata/employeeID">
<employeedata>
<employeeID><xsl:value-of select="employeeID" /></employeeID>
<employeename><xsl:value-of select="employeename" /></employeename>
<employeelocation><xsl:value-of select="employeelocation"
/></employeelocation>
<salary><xsl:value-of select="$xml2/employeedata/salary" /></salary>
<payzone><xsl:value-of select="$xml2/employeedata/payzone" /></payzone>
</employeedata>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

"Tarren" <noemailplease@thankyou> wrote in message
news:uwE3m$AoEHA.4032@TK2MSFTNGP15.phx.gbl...
> Hi:
>
> Here is the challenge I am faced with.
>
> I have two XML strings
>
> This one comes from Personnel
> <employeedata>
> <employeeID>1234</employeeID>
> <employeename>John Smith</employeename>
> <employeelocation>US</employeelocation>
> </employeedata>
>
> This one comes from HR
> <employeedata>
> <employeeID>1234</employeeID>
> <salary>40000</salary>
> <payzone>4</payzone>
> </employeedata>
>
> The result I need is this
> <employeedata>
> <employeeID>1234</employeeID>
> <employeename>John Smith</employeename>
> <employeelocation>US</employeelocation>
> <salary>40000</salary>
> <payzone>4</payzone>
> </employeedata>
>
> The books I have do not deal with this kind of scenario.
>
> Is this easier to do with XSLT Stylesheet or programmatically (I am using

VB
> .NET). Has anyone dealt with or have any example code of either an XSLT
> approach or using an XMLDocument in VB .NET.
>
> Thanks for your help!
>
>



Tarren

2004-09-22, 11:21 am

thanks, I will try this.

"Jonathan Chong" <jonathan@3exp.com> wrote in message
news:e8B3E0EoEHA.2900@TK2MSFTNGP12.phx.gbl...
> You can try this:
>
> <?xml version='1.0'?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:param name="xml2" select="document('hr.xml')"/>
>
> <xsl:template match="/">
> <table>
> <xsl:apply-templates select="/" mode="personneldata"/>
> </table>
> </xsl:template>
>
> <xsl:template match="employeedata" mode="personneldata">
> <xsl:choose>
> <xsl:when test="employeeID = $xml2/employeedata/employeeID">
> <employeedata>
> <employeeID><xsl:value-of select="employeeID" /></employeeID>
> <employeename><xsl:value-of select="employeename" /></employeename>
> <employeelocation><xsl:value-of select="employeelocation"
> /></employeelocation>
> <salary><xsl:value-of select="$xml2/employeedata/salary" /></salary>
> <payzone><xsl:value-of select="$xml2/employeedata/payzone" /></payzone>
> </employeedata>
> </xsl:when>
> </xsl:choose>
> </xsl:template>
> </xsl:stylesheet>
>
> "Tarren" <noemailplease@thankyou> wrote in message
> news:uwE3m$AoEHA.4032@TK2MSFTNGP15.phx.gbl...
> VB
>
>



Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews