Subject: Joining 2 or more XML files
Posted By: codesamurai Post Date: 1/24/2006 2:27:51 PM
Suppose I have state.xml and address.xml. state.xml has the state name, abbreviation, and its capital city. address.xml has person's name, street address, city, state, zip code. When I open address.xml and go to address that has new york in state, I want to extend address.xml to reference state.xml and display the new york abbreviation and if i go to an address with new jersey, I want it is abbreviation and...so now and so now. How do I do that?
Reply By: mhkay Reply Date: 1/25/2006 3:39:25 AM
Something like this. Use address.xml as the principal input document. Do

<xsl:variable name="addresses" select="/"/>
<xsl:variable name="states" select="document('state.xml')"/>

<xsl:template match="address">
  <address>
    <xsl:copy-of select="*"/>
    <xsl:copy-of select="$states/states/state[name=current()/state]/abbreviation"/>
  </address>
</xsl:template>

If the look-up table is large, you can use keys (xsl:key) for greater efficiency.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: codesamurai Reply Date: 1/25/2006 7:39:33 AM
thanks

Go to topic 39149

Return to index page 386
Return to index page 385
Return to index page 384
Return to index page 383
Return to index page 382
Return to index page 381
Return to index page 380
Return to index page 379
Return to index page 378
Return to index page 377