Click to See Complete Forum and Search --> : xsl namespace question
jdoy
November 28th, 2003, 05:39 AM
Hi all,
Well i've done an xsl stylesheet to transform an xml document to an xsd schema ( =>we then see our xml document like a xsd schema..)
But i have a problem: for every element of the created XSD schema, it appears a namespace which i don't want!!!
Look!! It's this namespace, and i don't know how to do in my xsl stylesheet for erase it!!
<xs:element name="getTasks_for_ptf" xmlns:xs="http://www.w3.org/1999/XMLSchema">
<xs:complexType>
<xs:sequence>
<xs:element name="id" />
<xs:element name="ptf">
<xs:complexType>
<xs:attribute name="URI" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="TableModel" use="required" />
<xs:attribute name="returns a TableModel of tasks filtered by portfolio (ORGA service)" use="optionnal" />
</xs:complexType>
</xs:element>
It would be very nice if one of you could help.. Thanks in advance
jdoy
November 28th, 2003, 08:39 AM
ok, i resolved this problem...
But now another one appears and here, i really don't know how to proceed....
How to generate the correct namespace.....
I have this result:
<?xml version="1.0" encoding="UTF-16"?>
<xs:schema xmlns:xs="http://www.w3c.org/2001/XMLSchema">
instead of this one:
<?xml version="1.0" encoding="UTF-16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:agenda="http://www.agenda.org" elementFormDefault="qualified" attributeFormDefault="qualified">
It could me so nice if someone could help me... I really need to have this right namespace instead of the one i receive....
Thanx a lot
khp
November 28th, 2003, 02:03 PM
Perhaps you could show us the stylesheet you are using ? and a sample xml document.
It's very difficult to tell you what to change, when we don't know what you are doing.
If you are still using something that resembles the stylesheet I suggested in your other thread, I would suggets changing the line
<xs:schema xmlns:xs="http://www.w3c.org/2001/XMLSchema">
to
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:agenda="http://www.agenda.org" elementFormDefault="qualified" attributeFormDefault="qualified">
In the stylesheet, but that just seems a little too obvious :)
jdoy
December 1st, 2003, 03:24 AM
Well ok, thanks for your answer.. It's almost ok, but not yet... I've alredy tried to do what you told me, but it's too obvious as you mentionned...
In fact, it appears a namespace i don't need, have a look to the code following:
XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:taglib="http://www.taglib.org" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:template match="/">
<xs:schema xmlns:xs="http://www.w3c.org/2001/XMLSchema">
<!-- le premier élément représente le nom de la taglib-->
..........
..........
then i apply this transformation to the xml file --> XSD:
<?xml version="1.0" encoding="UTF-16"?>
<xs:schema xmlns:xs="http://www.w3c.org/2001/XMLSchema">
<xs:element name="date">
<xs:complexType>
..........
..........
But normally, THIS has to appears to have a right formated XSD file:
<?xml version="1.0" encoding="UTF-16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:taglib="http://www.taglib.org">
<xs:element name="date">
<xs:complexType>
...........
...........
But no....So i really don't understand why this namespaces are incorrect.... The problem is that i always have to modify them.....
I attached to entire XSL file to you to have an example... If you have other ideas, there are of course welcomed
jdoy
December 1st, 2003, 03:29 AM
Oh, i forgot to tell you that all i'm working on is done with XMLSpy 5 under winXP...
Thanx.....
khp
December 1st, 2003, 08:52 PM
Hi
Sorry about my late response, I have been very busy, the last few days.
Unfortunatly I don't really have alot tell you, as I said in my first response to your postings, setting the namespace in the output document can be somewhat tricky. On top of that MS's XML implementation, which I assume XMLSpy is based on, is not quite standard compliant.
I just did a few quick tests in xalan, and I have no problem setting the namespace in the output document, by either explecitly setting the xmlns:taglib attribute on the root output node. Or by only having it in the stylesheet node, in which case xalan will insert the namespace decelaration when it's needed.
jdoy
December 2nd, 2003, 03:25 AM
No problem, it's already great all you helped.... But i have one last question: what do you mean with "either explecitly setting the xmlns:taglib attribute on the root output node"??
could you give me an example of what you're talking about??
Thanx
Jerome
khp
December 2nd, 2003, 02:14 PM
OK
I have an xml file like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<tag>
<function>foo</function>
</tag>
And this xsl file, which explicitly the sets the namespace declerations on the xs:schema node.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:taglib="http://www.taglib.org" version="1.0">
<xsl:template match="/">
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:taglib="http://www.taglib.org">
<xsl:apply-templates select="*"/>
</xs:schema>
</xsl:template>
<xsl:template match="function">
<xs:element>
<xs:annotation>
<taglib:foo>
<taglib:bar>
<xsl:value-of select="text()"/>
</taglib:bar>
</taglib:foo>
</xs:annotation>
</xs:element>
</xsl:template>
</xsl:stylesheet>
This produces the following output
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:taglib="http://www.taglib.org">
<xs:element>
<xs:annotation>
<taglib:foo>
<taglib:bar>foo</taglib:bar>
</taglib:foo>
</xs:annotation>
</xs:element>
</xs:schema>
Alternativly we could use this stylesheet
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:taglib="http://www.taglib.org" version="1.0">
<xsl:template match="/">
<xs:schema>
<xsl:apply-templates select="*"/>
</xs:schema>
</xsl:template>
<xsl:template match="function">
<xs:element>
<xs:annotation>
<taglib:foo>
<taglib:bar>
<xsl:value-of select="text()"/>
</taglib:bar>
</taglib:foo>
</xs:annotation>
</xs:element>
</xsl:template>
</xsl:stylesheet>
In Which case I get the same result as above, in this example, but on larger examples the namespace decleration migt be moved, to another element, depending on, where it's needed.
jdoy
December 3rd, 2003, 03:49 AM
No problem, IT WORKS!!!!!!! Thanx very much one more time
Jerome
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.