Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Normalizing XML data
Message
 
À
05/08/2003 23:54:45
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
XML
Divers
Thread ID:
00817166
Message ID:
00818910
Vues:
14
Hi Keith,

This might be totally useless, but this is the way I use relationships between XML documents:

1) Consider the two XML documents bellow (Orders and Products):

--- Orders ---
<?xml-stylesheet type="text/xsl" href="OrdersProducts.xsl" ?>
<Orders> 

  <Order id="1"> 
    <Item id="1"> 
      <Qty>10</Qty> 
    </Item> 
    <Item id="2"> 
      <Qty>1</Qty> 
    </Item> 
  </Order> 

  <Order id="2"> 
    <Item id="1"> 
      <Qty>1</Qty> 
    </Item> 
  </Order> 

  <Order id="2"> 
    <Item id="2"> 
      <Qty>1</Qty> 
    </Item> 
  </Order> 

</Orders> 
--- Products ---
<Products> 
  <Product id="1"> 
    <Description>Produto One</Description> 
  </Product> 
  <Product id="2"> 
    <Description>Produto Two</Description> 
  </Product> 
</Products> 
Bu using the xsl:document() function we are able to reference nodes from an external XML document. The followinf XSLT document shows how we could present a report displaying the orders and related items:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

   <xsl:template match="/">
      <xsl:apply-templates select="//Orders"/>
   </xsl:template>

  <xsl:template match="Order">
      <b>Pedido: <xsl:value-of select="@id" /> </b> <br/>
      <xsl:apply-templates select="Item"/>
  </xsl:template>

  <xsl:template match="Item">
      <xsl:variable name="IDProduto" select="@id" />
      <xsl:value-of select="$IDProduto" /> <br/>
      <xsl:value-of select="document('Products.Xml')/Products/Product[@id=$IDProduto]/Description" /> <br/>
  </xsl:template>

</xsl:stylesheet>
HTH.
-----
Fabio Vazquez
http://www.fabiovazquez.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform