Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2006, 02:16 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML To XML, using XSL & XSD

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.
 
Old April 8th, 2006, 02:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
XML to XSD gagsy Pro Java 0 March 3rd, 2008 02:38 AM
Converting Source Xml into Target Xml Using XSL. alapati.sasi XSLT 3 May 14th, 2007 10:54 AM
Validating XML against XSD ShaileshShinde General .NET 0 September 20th, 2005 01:22 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
ASP with xml (along with .xsd) software_developer_kk Classic ASP Basics 0 April 18th, 2005 12:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.