[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Jyotsna,
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.
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:
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 |
Jyotsna,
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:stylesheet...> <xsl:output method="text"/> <xsl:template match="/config/server"> insert into server ( 'oracleAppVersion',java-version,java-vendor, java-vm-version,java-vm-vendor,java-vm-name,os-arch,os-name,os-version ) 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"/> ); </xsl:template> </xsl:stylesheet>
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
('oracleAppVersion',java-version,java-vendor,
java-vm-version,java-vm-vendor,java-vm-name,os-arch,os-name,os-version
)
values('1.0','1.1.9.0','vendorcl','1.2','vendvmor','virtual','a','bb','ccc')
;
I tried using XMLSpy feature "Create DB structure from
XML Schema" but its not helping to customize the output ..so 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
(http://www.altova.com)-->
<config xmlns="http://xxx.y.com/c/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=http://xxx.y.com/c/ id="String">
<domain-name>oracle appserver</domain-name>
<timestamp>2001-12-17T09:30:47.0Z</timestamp>
<server is-admin-server="false" name="String">
<company>
<server-version>1.0</server-version>
</company>
<java>
<version>1.1.9.0</version>
<vendor>vendorcl</vendor>
<vm>
<version>1.2</version>
<vendor>vendvmor</vendor>
<name>virtual</name>
</vm>
</java>
<os>
<arch>a</arch>
<name>bb</name>
<version>ccc</version>
</os>
</server>
</config>
---------------------------
configdetail.xsd - XSD Schema that it macthes
------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://y.com" xmlns:inv="http://y.com/c"
targetNamespace="http://y.com/c"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://y.com/c"
schemaLocation="../../configmain.xsd"/>
<xs:complexType name="configdetailtype">
<xs:complexContent>
<xs:extension base="cfg:ConfigmainType">
<xs:sequence>
<xs:element name="server" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="oracleAppVersion"
type="xs:string"/>
<xs:element name="java">
<xs:complexType>
<xs:sequence>
<xs:element name="version" type="xs:string"/>
<xs:element name="vendor" type="xs:string"/>
<xs:element name="vm">
<xs:complexType>
<xs:sequence>
<xs:element name="version" type="xs:string"/>
<xs:element name="vendor" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="os">
<xs:complexType>
<xs:sequence>
<xs:element name="arch" type="xs:string"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="version" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"
use="required"/>
<xs:attribute name="adminServer" type="xs:boolean"
use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
I can give me more explaination if needed. Thanks a lot for your response Jyotsna
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
!DSPAM:446e5ab9193171715718467!
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] [ XSLT ] Dynamically Transfor, Jyotsna B | Thread | RE: [xsl] [ XSLT ] Dynamically Tran, Michael Kay |
[xsl] [ XSLT ] Dynamically Transfor, Jyotsna B | Date | RE: [xsl] [ XSLT ] Dynamically Tran, Michael Kay |
Month |