Simple (?) output of attributes with XSLT does not work

Harry Zoroc

Usenet Archive
Joined
Jul 7, 2004
Messages
6
Reaction score
0
I would like to treat an xsd Schema file as XML file and to display the targetNamespace and all the imports. That's it. But the following does not work. Why?

I did not enter the stylesheet in the xsd file directly but tried to compute the output on the command line e.g. with xalan like:

java net.sf.saxon.Transform -o myout.html myschema.xsd myxsltfile.xslt

Using Saxon yields no better result. The produced myout.html contains all HTML tags and a lot of tabulators but no filtered contents from the xsd file.

Both XSLT processor work for other xml/XSLT formattings. So it's not an error of the xslt procs setup.

So what's wrong with the xslt stylesheet?

Harry

myschema.xsd (beginning):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<schema targetNamespace="http://www.blah.org/aaa" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xhtml="http://www.w3.org/1999/xhtml" elementFormDefault="qualified"> <import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="ddd.xsd"/> <import namespace="http://www.foo.com/bbb" schemaLocation="bbb.xsd"/> <import namespace="http://www.zock.net/ccc" schemaLocation="ccc.xsd"/> .....

myxsltfile.xslt:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:eek:utput method="html"/> <xsl:template match="/"> <HTML> <HEAD> <TITLE>Test</TITLE> </HEAD> <BODY> targetNamspace=<xsl:apply-templates select="/schema"/>
Imports:
<TABLE border="1">
<TR><TH>Namespace</TH><TH>SchemaLocation</TH></TR>
<xsl:apply-templates select="/schema/import"/>
</TABLE>
</BODY>
</HTML>
</xsl:template>

<xsl:template match="/schema">
<xsl:value-of select="@targetNamespace"/>
</xsl:template>

<xsl:template match="/schema/import">
<TR>
<TD><xsl:value-of select="@namespace"/></TD>
<TD><xsl:value-of select="@schemaLocation"/></TD>
</TR>
</xsl:template>
</xsl:stylesheet>
 

Henry S. Thompson

Usenet Archive
Joined
Jan 14, 2000
Messages
309
Reaction score
0
Valid schema documents, including yours, are in the
http://www.w3.org/XMLSchema namespace. You need to include a namespace declaration for that namespace, e.g.

xmlns:xs="http://www.w3.org/XMLSchema"

on the root of your stylesheet, and us e.g.

<xsl:template match="/xs:schema/xs:import">

to access it.

Note because of the way XPath 1.0 is defined, just adding a default namespace declaration for the W3C XML Schema namespace will _not_ fix your stylesheet.

ht
 

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
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top