|
Subject:
|
XML To XML, using XSL & XSD
|
|
Posted By:
|
supercop75
|
Post Date:
|
4/8/2006 2:16:28 AM
|
Would like some suggestion to handle a scenario. Situation consists of Access 2003 , Xml, Xsd & Xsl. Ms Access 2003 allows to export data of a table as xml.
Lets say i have a table "mytable" in msaccess 2003 database, whose structural definition goes like: ---------------- Id integer Name string[40] age smallint ----------------
Exporting this table generates following XML:
----------------------- <?xml version="1.0" encoding="UTF-8"?> <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"> <MyTable> <Id>1</Id> <Name>Jack</Name> <Age>24</Age> </MyTable> <MyTable> <Id>2</Id> <Name>John</Name> <Age>32</Age> </MyTable> <MyTable> <Id>3</Id> <Name>Russhel</Name> <Age>27</Age> </MyTable> </dataroot> -----------------------
I need to generate Oracle compliant XML from this using XSL, but at the same time i want to keep transformation dynamic, by keeping mapping information of Access table fields to that of oracle table fields.
Map information can be: ======================= Access Oracle ======================= Id oSeqId Name oFullName Age oAge -----------------------
Questions:
1. How do i keep this mapping information (ofcourse along with data type & other stuff per field/element) in a single or multiple file XSD. 2. How to Use this XSD file in a XSL to tranform the Access generated XML into Oracle compliant XML.
I have to follow the norms of not hard coding any field name in XSL, just to read the field-to-field relation from XSD file(s) & Finding Access-fieldname in access-generated XML, reading its data value and transforming it into another XML but with Oracle field information picked from same XSD.
---------------------------- Probable Oracle compliant XML ---------------------------- <?xml version = '1.0'?> <ROWSET> <ROW num="1"> <oSeqId>1</oSeqId> <oFullName>Jack</oFullName> <oAge>24</oAge> </ROW> <ROW num="2"> <oSeqId>2</oSeqId> <oFullName>John</oFullName> <oAge>32</oAge> </ROW> <ROW num="3"> <oSeqId>3</oSeqId> <oFullName>Russhel</oFullName> <oAge>27</oAge> </ROW> </ROWSET> ----------------------------
Please provide some suggestion and sample code-snippet would be an added advantage in understanding, reason being i am bit new in XML/XSL/XSD stuff.
Thanks in advance.
|
|
Reply By:
|
mhkay
|
Reply Date:
|
4/8/2006 2:48:13 AM
|
I wouldn't keep the mapping information in an XSD schema, I would keep it in a separate mapping file:
<mapping> <column access="Id" oracle="oSeqId"/> ...
Then you can load the mapping file into your stylesheet:
<xsl:variable name="mappings" select="document('mappings.xml')"/>
and define a key for fast access:
<xsl:key name="m" match="mapping" use="@access"/>
and then process your table as
<xsl:for-each select="*"> <xsl:element name="key('m', name(), $mappings)"> <xsl:value-of select="."/> </xsl:element> </xsl:for-each>
This is a 2.0 solution (the call to key() with 3 arguments). It's a bit more complicated in 1.0 to access a key in another document, but you get the general idea.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|