XML document with schema and stylesheet

A

Andre-John Mas

Hi,

I have an XML document which looks as follows is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="visitreport.xsl"?>
<VisitReport xmlns="http://reports.myco.com" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://reports.myco.com xsd/
VisitReport.xsd">
<Visit>
<visitId>138146</visitId>
<date>2007-06-06</date>
</Visit>

this makes reference to both a style sheet and a schema ( I have
provided the XSL at the end ). what I find is that if I include the
'xmlns=' attribute to VisitReport the table header gets displayed, but
none of the data (tested with Firefox and IE). On the other hand if I
remove the attribute it displays properly. Can these appear together
or are they exclusive?

To provide a bit of context, I am wanting to provide an XML output by
my web site, in a such a way that it can be displayed by the web
browser in tabular form, or saved and imported by Excel. Providing the
stylesheet only approach the web page displays properly, but Excel
does not know what the data types are, but if I provide only the
'xmlns=' then Excel knows the data types, but it does not get rendered
by the web browser. Should I be generating two version of the XML
document depending on the use?

Andre


---- The XSL ----

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:eek:utput method="html" />
<xsl:template match="/VisitReport">

<html>
<head>
<link rel="stylesheet" type="text/css" href="golden.css" />
</head>
<body>
<h2>Visit Report</h2>
<table border="0">
<thead>
<tr>
<th>Visit ID</th>
<th>Name</th>
</tr>
</thead>

<tbody>
<xsl:for-each select="Visit">

<tr class="even">
<xsl:if test="position() mod 2 = 1">
<xsl:attribute name="class">odd</xsl:attribute>
</xsl:if>
<td><xsl:value-of select="visitId"/></td>
<td><xsl:value-of select="name"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
 
M

Martin Honnen

Andre-John Mas said:
<?xml-stylesheet type="text/xsl" href="visitreport.xsl"?>
<VisitReport xmlns="http://reports.myco.com" xmlns:xsi="http://
www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://reports.myco.com xsd/
VisitReport.xsd">

Why are you using the noNamespaceSchemaLocation attribute if your
elements are in the namespace http://reports.myco.com? That does not
make sense at all. You should use the xsi:schemaLocation attribute instead.
<Visit>
<visitId>138146</visitId>
<date>2007-06-06</date>
</Visit>

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

Add a namespace declaration
xmlns:ns="http://reports.myco.com"
to the stylesheet, then use that prefix 'ns' in XPath expressions and
match patterns to qualify element names e.g.
<xsl:template match="/VisitReport">
said:
<xsl:for-each select="Visit">
<xsl:for-each select="ns:Visit">
and so on.
 
A

Andre-John Mas

Thanks, this does the job :)

Andre

Why are you using the noNamespaceSchemaLocation attribute if your
elements are in the namespacehttp://reports.myco.com?That does not
make sense at all. You should use the xsi:schemaLocation attribute instead.


Add a namespace declaration
xmlns:ns="http://reports.myco.com"
to the stylesheet, then use that prefix 'ns' in XPath expressions and
match patterns to qualify element names e.g.




<xsl:for-each select="ns:Visit">
and so on.
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top