Re: [xsl] [ XSLT ] Dynamically Transform xml pages to database queries

Subject: Re: [xsl] [ XSLT ] Dynamically Transform xml pages to database queries
From: Raffaele Sena <raff@xxxxxxxxxxxx>
Date: Fri, 19 May 2006 21:09:01 -0700

you don't mention which language you want to use to write write your application. I am assuming is Java but the answer should apply to any language for which you have an XSLT engine.

1) how to read each file from a folder ?
Use the filesystem API. XSLT cannot help you with this.
Once you have the file name you can read your document into a DOM or even better use SAX to stream it to the XSLT processor.

2) how to write a template that generate text:
<xsl:output method="text"/>
<xsl:template match="/config/server">
 insert into server (
 ) values (
  <xsl:value-of select="company/server-version"/>,
  <xsl:value-of select="java/version"/>,
  <xsl:value-of select="java/vendor"/>,
  <xsl:value-of select="java/vm/version"/>,
  <xsl:value-of select="java/vm/vendor"/>,
  <xsl:value-of select="java/vm/name"/>,
  <xsl:value-of select="os/arch"/>,
  <xsl:value-of select="os/name"/>,
  <xsl:value-of select="os/version"/>

Note that I left out the namespace (I am lazy) so if you try this as-is your output will be empty.

I suggest you start with a command line XSLT processor (or use XMLSpy) and a static xml file. When you get that to work you can think about writing a program that runs the conversion.

Hope this helps,

-- Raffaele

Jyotsna B wrote:
Hi All,
I am NEWbie to XSLT and in process of learning.Any
code suggestions or direction is greatly appreciated
I have a list of XML files at certain location (ex:
D:\xmlfilesloc )
I need to write a program which checks the folder
automatically and if files exists -reads each xml file
at a time and transforms the xml file (using XSLT ) to
bunch of customized oracle database queries .
Questions :
1)How to read each xml file from a specified location
dynamically ?
2)How to use XSLT to transform a xml file
dynamically/automatically to bunch of customized
database queries (elements to table name mapping ;
attributes to columns names ;...etc )? -------------------------------------------
Ex Output I am trying to acheive is queries :- -------------------------------------------
insert into server

I tried using XMLSpy feature "Create DB structure from
XML Schema" but its not helping to customize the output I
want to code myself the XSLT transformation to get
desired output queries -------------------------------
Example of Input XML file :-
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSpy v2006 sp1 U
<config xmlns="";
xsi:schemaLocation= id="String">
<domain-name>oracle appserver</domain-name>
<server is-admin-server="false" name="String">
configdetail.xsd - XSD Schema that it macthes
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="";
xmlns=""; xmlns:inv="";
<xs:import namespace="";
<xs:complexType name="configdetailtype">
<xs:extension base="cfg:ConfigmainType">
<xs:element name="server" minOccurs="0"
<xs:element name="oracleAppVersion"
<xs:element name="java">
<xs:element name="version" type="xs:string"/>
<xs:element name="vendor" type="xs:string"/>
<xs:element name="vm">
<xs:element name="version" type="xs:string"/>
<xs:element name="vendor" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="os">
<xs:element name="arch" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="version" type="xs:string"/>
<xs:attribute name="name" type="xs:string"
<xs:attribute name="adminServer" type="xs:boolean"

I can give me more explaination if needed.
Thanks a lot for your response

Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around


Current Thread