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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using XSLT to merge 2 XML

Status
Not open for further replies.

modinrico

Programmer
Apr 30, 2008
8
US
This Should be simple but ugh who knows these days ;)

I have this XSLT that i am using to try and merge 2 XML documents programamtically. Basically 1 document will be used to fill in gaps on the second document.
I understand now how to load a document inta variable and use that but what happens when i try to go and use the original document that the XSLT is being applied to.

LIke the following. It doesn't recognize this or something because I don't get any data back from this statement but this statemtn seems to be what i want. Any Ideas??

<xsl:for-each select="ToSales/Customer/Model/Standard/Elevation"> <--- THis is the line that stops working Any help is appreciated...

Rico





<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:eek:utput method="xml" indent="yes"/>

<!-- load the merge file -->
<xsl:variable name="ssnetData"
select="document('ssnetlayout.xml')"/>

<xsl:template match="/">

<salescenterimport>
<builder action="update" >
<xsl:attribute name="code">
<xsl:value-of select="$ssnetData/builder/@code" />
</xsl:attribute>
<name>
<xsl:value-of select="$ssnetData/builder/@name" />
</name>
<county>
<xsl:value-of select="$ssnetData/builder/@country" />
</county>
</builder>

<xsl:for-each select="$ssnetData/builder/division">
<division action="update">
<code>
<xsl:value-of select="@code" />
</code>
<name>
<xsl:value-of select="@name" />
</name>


<xsl:for-each select="ToSales/Customer/Model/Standard/Elevation">
<option action="update">
<code>
<xsl:value-of select="@ID" />
</code>
<description>
<xsl:value-of select="@Description" />
</description>
<longdescription>
<xsl:value-of select="@BaseComment" />
</longdescription>
<price>
<xsl:value-of select="@PkgAmount" />
</price>
</option>
</xsl:for-each>


</division>
</xsl:for-each>

</salescenterimport>
</xsl:template>
</xsl:stylesheet>
 
As such it is kind of Cartesian product..., make sure that's what you want. To do it, you need to hold the context node of the original document in a variable and reference to it when needed.
[tt]
<xsl:template match="/">
[blue]<xsl:variable name="local" select="." />[/blue]
<!-- etc etc... -->
<xsl:for-each select="[blue]$local/[/blue]ToSales/Customer/Model/Standard/Elevation">
<!-- etc etc ... -->
</xsl:for-each>
<!-- etc etc... -->
</xsl:template>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top