Click to See Complete Forum and Search --> : transform XSD into XML


jdoy
December 5th, 2003, 04:57 AM
Hi all,

Well, one more time i have a (basic) question... I need to transform this time an X file to an XML file with an XSL stylesheet transformation, but i don't exactly how to proceed especially with the namespaces....

Look, by example i have this XSD file:



<xs:element name="today">
<xs:complexType>
<xs:sequence>
<xs:element name="field">
<xs:complexType>
<xs:attribute name="int" use="required"/>
<xs:attribute name="false" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="delta">
<xs:complexType>
<xs:attribute name="int" use="required"/>
<xs:attribute name="false" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="date" use="required"/>
<xs:attribute name="public" use="optional"/>
<xs:attribute name="purpose" use="optional" default="Return today at 00h00'00''"/>
</xs:complexType>
</xs:element>




and as result i'd like to have this corresponding XML sample:

<function scope="public" name="today" purpose="Return today at 00h00'00''">

<return-type>date</return-type>
<parameter by-ref="false">
<name>field</name>
<type>int</type>
</parameter>
<parameter by-ref="false">
<name>delta</name>
<type>int</type>
</parameter>
</function>




So how can i do that through an XSL stylesheet??? Thanx a lot for helping if you can....

jdoy
December 5th, 2003, 05:00 AM
The first sample of code is a XSD file... I forgot the SD while typing...

So what i like to do is transform XSD into XML with XSL...

Thanx a lot


Jerome

jdoy
December 5th, 2003, 08:17 AM
Well i try to this, but it doesn't work at all, it gives a empty result:

My XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:taglib="http://www.taglib.org" version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="element"/>
</xsl:template>
<xsl:template match="element">
<xsl:variable name="name" select="@name"></xsl:variable>
<xsi:taglib><xsl:value-of select="$name"/></xsi:taglib>

</xsl:template>
</xsl:stylesheet>



and it gives me this result:

<?xml version="1.0" encoding="UTF-16"?>

But there's no more... There must have a mistake either in the namespace or in the stylesheet or perhaps both, but i don't see it....

It would be very nice of you if you could help....

Thanx a lot

Jerome

khp
December 6th, 2003, 05:57 AM
The templates has to match not just the name of the elements but also the name space. So to match a schema element node you have to declare the xs namespace and write
<xsl:template match="xs:element">
Or you could rewrite the template match as *[name()='element']