Could someone help me out with my namespace problems in my XSD

M

Mike_August

Could someone help me out with the following?

I've got
1)an xml file
2)an xsl
3)a schema

My namespaces are as follow

molecular_db.xml
<database
xmlns="http://www.mine.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mine.com mdb_schema.xsd"
mdb_schema.xsd
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.mine.com"
targetNamespace="http://www.mine.com"
elementFormDefault="qualified">

dB_ss.xsl
<xsl:stylesheet version = "1.0"
xmlns="http://www.mine.com"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
When I try it out in XMLWriter I keep getting an error that states I
can't use xs:element in the context defined as
xsi:schemaLocation="http://www.mine.com mdb_schema.xsd".

Hence, all I get for output are the headers I defined in the xsl. Take
away the xsd declarations and everything is fine. Better yet, take-away
the xmlns declaration in my xml file and it doesn't look for the xsd and
the file displays fine, headers and data all formatted by the xsl.
What's wrong with my file and how do I fix it?
 
M

Martin Honnen

Mike_August wrote:

My namespaces are as follow

molecular_db.xml
<database
xmlns="http://www.mine.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mine.com mdb_schema.xsd"

mdb_schema.xsd
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.mine.com"
targetNamespace="http://www.mine.com"
elementFormDefault="qualified">

dB_ss.xsl
<xsl:stylesheet version = "1.0"
xmlns="http://www.mine.com"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

If your XSLT stylesheet is supposed to have XPath expressions and match
patterns matching any of the elements in the http://www.mine.com
namespace then you need a prefix e.g.
xmlns:pf="http://www.mine.com"
bound to the namespace URI and then use that prefix e.g.
<xsl:template match="pf:database">
That has to happen in the XSLT stylesheet only so no change to the XML
or schema is needed.
 
M

Mike_August

Martin said:
Mike_August wrote:




If your XSLT stylesheet is supposed to have XPath expressions and match
patterns matching any of the elements in the http://www.mine.com
namespace then you need a prefix e.g.
xmlns:pf="http://www.mine.com"
bound to the namespace URI and then use that prefix e.g.
<xsl:template match="pf:database">
That has to happen in the XSLT stylesheet only so no change to the XML
or schema is needed.
I'm not using a template. Besides if I change xsl:stylesheet to
xsl:template match="pf:database: and place mlns:pf="http://www.mine.com"
in my database xml file then I just get a 'xsl:stylesheet' does not
match start tag 'xsl:template'. And so this does not solve the problem.

Mike
 
M

Martin Honnen

Mike_August wrote:

I'm not using a template. Besides if I change xsl:stylesheet to
xsl:template match="pf:database: and place mlns:pf="http://www.mine.com"
in my database xml file then I just get a 'xsl:stylesheet' does not
match start tag 'xsl:template'. And so this does not solve the problem.

So your XSLT stylesheet is empty besides the xsl:stylesheet element?
Surely you have
xsl:template
instructions in your XSLT stylesheet? Hmm, indeed you have only
<xsl:template match="/">
but of course I wrote the above as an example and explictly mentioned
XPath expressions and match patterns.
The advice is correct, the stylesheet needs to bind a prefix to the
namespace URI and the XPath expressions need to use that e.g.
<xsl:for-each select="pf:database/pf:molecule">
 
M

Mike_August

Martin said:
Mike_August wrote:




So your XSLT stylesheet is empty besides the xsl:stylesheet element?
Surely you have
xsl:template
instructions in your XSLT stylesheet? Hmm, indeed you have only
<xsl:template match="/">
but of course I wrote the above as an example and explictly mentioned
XPath expressions and match patterns.
The advice is correct, the stylesheet needs to bind a prefix to the
namespace URI and the XPath expressions need to use that e.g.
<xsl:for-each select="pf:database/pf:molecule">

Right, did you check your advice on my file? I'll check it out soon. So
I'm supposed to apply the pf namespace for all elements, or just the
for-each tags?
 
M

Martin Honnen

Mike_August wrote:

So
I'm supposed to apply the pf namespace for all elements, or just the
for-each tags?

Any XPath expression to match/select elements in that namespace needs to
have prefix:localname and not simply localname.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top