Section 12.5.  Applying a transform on export

Prev don't be afraid of buying books Next

12.5. Applying a transform on export

In some cases, you may want the exported XML to conform to a particular schema, rather than using the names and structure of the Access database. For example, if you are exporting an order that is to be used in an e-commerce transaction, you may need it to conform to a specific e-commerce schema.

Suppose you have agreed on such a schema with your customers. An example of a conforming exported order is shown in Example 12-5.

Example 12-5. Order conforming to a different schema (order diff structure.xml)
 <?xml version="1.0" encoding="UTF-8"?> <order xmlns="http://xmlinoffice.com/orders"        number="1001">   <date>2004-02-15T00:00:00</date>   <customer>Doug Jones</customer>   <shipTo>     <addr>123 Main St.</addr>     <city>Arlington</city>     <state>VA</state>     <postal_code>22205</postal_code>   </shipTo>   <items>     <item number="219">       <quant>1</quant>       <size>L</size>     </item>     <item number="334">       <quant>1</quant>       <size>L</size>     </item>   </items> </order> 

To accomplish this, you can transform the XML when you export it using an XSLT stylesheet. The stylesheet shown in Example 12-6 will transform the default export of the orders database into a new order that conforms to our desired schema.

Example 12-6. Transforming the order on export (order transform for export.xsl)
 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"                 xmlns:ord="http://xmlinoffice.com/orders"> <xsl:template match="/dataroot">   <ord:order number="1001">     <xsl:attribute name="number">       <xsl:value-of select="//ORD_NUM"/>     </xsl:attribute>     <ord:date><xsl:value-of select="//DATE"/></ord:date>     <ord:customer>       <xsl:value-of select="//CUST_NAME"/>     </ord:customer>     <ord:shipTo>       <ord:addr><xsl:value-of select="//ADDRESS"/></ord:addr>       <ord:city><xsl:value-of select="//CITY"/></ord:city>       <ord:state><xsl:value-of select="//STATE"/></ord:state>       <ord:postal_code>         <xsl:value-of select="//ZIP"/>       </ord:postal_code>     </ord:shipTo>     <ord:items>       <xsl:apply-templates select="//ORDERS[1]/ORDER_ITEMS"/>     </ord:items>   </ord:order> </xsl:template> <xsl:template match="ORDER_ITEMS">   <ord:item>     <xsl:attribute name="number">       <xsl:value-of select="PROD_NUM"/>     </xsl:attribute>     <ord:quant><xsl:value-of select="QUANTITY"/></ord:quant>     <ord:size><xsl:value-of select="SIZE"/></ord:size>   </ord:item> </xsl:template> </xsl:stylesheet> 

You can specify the transform to be used on export on the Data tab of the Export XML dialog. Clicking Transforms takes you to the Export Transforms dialog, shown in Figure 12-13.

Figure 12-13. The Export Transforms dialog




To add a transformation, simply click Add and specify the name of the XSLT stylesheet.

The Export Transforms dialog lists all the available transforms. It is possible to add more than one transform to the list. However, only one will be applied on any given export: the one that is selected when OK is clicked.

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net