I don't know how to make this work the way you're trying to make it work, but why not do the checking in your code? That would make it easier (I'd think) to present appropriate error messages. (I don't know where they should go, unless the user is supposed to be able to add to or remove from the list of stylesheets.) If the incoming stylesheet has no definition of, and no reference to, the cdx namespace, wouldn't it validate? Won't you want to look at the attribute values; a systemid value of "123-456" should probably be rejected (if it's supposed to be a GUID).
(If you want to require all the metadata, shouldn't the attributes be required in your CdxStylesheet namespace?) At 07:15 AM 6/17/2004, Michael Wood wrote >I have an application that applies XSL Stylesheets to XML data to produce >HTML. The stylesheets are external files that exist in a directory and are >read in by the application. Each stylesheet is applied to the same XML, they >just provide different "views" of the same data (i.e., Summary info, detail >info, specific info, etc.). Since the files are stored externally the idea >is that they don't have any correlating information in the database, but >there is the desire to have certain metadata information for each >stylesheet, such as author, name, description, etc. > >The idea was to add a new namespace to the xslt document and use it to store >the metadata. This could then be read as the stylesheets were read by the >application. > >Example: > ><?xml version="1.0" encoding="UTF-8" ?> ><xsl:stylesheet version="1.0" >xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >xmlns:cdx="http://mycompany/stylesheets"> ><xsl:output method="html"></xsl:output> ><cdx:sheet name="Summary Info" description="Summary Info of order." >systemid="14653A6E-0A63-46D5-B2FE-EDD0BAE22A0C" >author="M. Wood"></cdx:sheet> ><xsl:template match="/"> ><HTML> > ...rest of stylesheet template.... ></HTML> ></xsl:template> ></xsl:stylesheet> > >Now, the plan was on application startup to look in this directory and >iterate the stylesheet files. Open each one and read them into a hashtable. >The meta data would be loaded as well and used to provide a dropdown later >in the application for a list of possible stylesheets to apply to the data. >We wanted to be able to validate the stylesheets to ensure they had the cdx >namespace and that it fit a schema (to ensure all the required fields were >filled out for the metadata; see scheme at end of email). Here is where I >ran into my issue. I can't seem to find a way to validate this stylesheet. > >My approaches so far: > >1) Use an XMLValidatingReader object to load in the stylesheet. As far as I >knew this was the only .Net object used to validate XML against a schema. >So, I attempted this. I added the schema file to the schema collection, but >on the Read method it died since the xsl >(http://www.w3.org/1999/XSL/Transform) namespace did not validate. I >thought, okay, all I need to do is add this schema to the collection, but >wait....that would require a physical schema file for XSL. Hmmm....doesn't >sound like a good thing to me. But, wait, VS.Net ships with one of these! >So, pop the xslt.xsd file into the schema collection and then it doesn't >like the embedded HTML in the templates. *Sigh* > >2) Before I was working on the validation of the stylesheets I was already >applying the stylesheets in a reference model by loading it up in the >XSLTransform object. This appeared to be validating the stylesheet against >the XSLT schema, but pretty much ignored the other namespace completely. I >could not find a way to get it to check the other namespace via it's schema. >The help specifically states, "if you have entities in your xsl that you >need to validate, use the XMLValidatingReader class". Hmmm, see above >frustration. I'm using the 1.1 Framework where over half of the Load >methods in the XSLTRansform object have been obsolete. > >So, what I really need to be able to validate the cdx namespace only in the >document and pretty much ignore the xsl namespace or the HTML in the >templates. > > > >Schema for the cdx namespace: >______________________________________ ><?xml version="1.0" ?> ><xs:schema id="CdxStylesheet" targetNamespace="http://mycompany/stylesheets" > xmlns:mstns="http://mycompany/stylesheets" >xmlns="http://mycompany/stylesheets" > xmlns:xs="http://www.w3.org/2001/XMLSchema" >xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" > attributeFormDefault="qualified" elementFormDefault="qualified"> > <xs:element name="sheet"> > <xs:complexType> > <xs:attribute name="name" form="unqualified" type="xs:string" /> > <xs:attribute name="description" form="unqualified" type="xs:string" /> > <xs:attribute name="systemid" form="unqualified" type="xs:string" /> > <xs:attribute name="author" form="unqualified" type="xs:string" /> > </xs:complexType> > </xs:element> ></xs:schema> J. Merrill / Analytical Software Corp =================================== This list is hosted by DevelopMentorŪ http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com