开发者

XSD: XSL stylesheet child element warnings in Visual Studio 2010

I have an XSD defined for a messaging application. As part of the message payload, I need to require that, for one of my elements, the content be an XSL stylesheet. This is used later in applying an XSL transformation to generate the final formatted output. Please note that the payload of the XSL stylesheet is an end-user decision, thus I cannot simply make an XSD to validate its contents. Ideally, it would be great if there was an XSD for HTML, because I would simply use that as the namespace for the non-XSL content in the stylesheet!

Thus, I did this (this is only part of the XSD, but you get the ideas):

<?xml version="1.0" encoding="Windows-1252"?>
<xs:schema targetNamespace="http://schemas.mycorpname.com/notification"
           attributeFormDefault="unqualified" elementFormDefault="qualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
           xmlns="http://schemas.mycorpname.com/notification">

        <xs:import namespace="http://www.w3.org/1999/XSL/Transform" />
        <xs:complexType name="renderinginstructions">
            <xs:sequence>
                <xs:element ref="xsl:stylesheet"></xs:element>
            </xs:sequence>
        </xs:complexType>
</xs:schema>

This works great, and forces the consumers to include an XSL stylesheet inside the <renderinginstructions> element.

Most of the time, the XSL stylesheet should include tags to output a valid HTML document. However, when I place child elements into the stylesheet definition, I get this error from Visual Studio:

XSD: XSL stylesheet child element warnings in Visual Studio 2010

If I want to require the presence of an embedded XSL stylesheet (and not any other content!), did I create my XSD properly? What else can I do? I don't like this warning.

Here is an example of the type of document that induces this warning.

NOTE: In the stylesheet, if I use xmlns="", I get the warning only. If I don't specify a default namespace, I do not get the warning, but I g开发者_如何学运维et a "Message" from Visual Studio stating:

"Could not find schema information for the element 'http://schemas.mycorpname.com/notification:html'".

So, with xmlns="", I get a Warning. Without it, I get tons of "Messages", all related to the child elements of xsl:template. Isn't the very purpose of XSLT to be able to put tons of various elements in the document? Are XSLT not subject to schema validation when they stand alone?

<?xml version="1.0"?>
<notification xmlns="http://schemas.mycorpname.com/notification">
    <renderinginstructions>
         <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="">
                    <xsl:template match="/">
                        <html>
                            <head>This is the head</head>
                            <body>This is the body.</body>
                        </html>
                    </xsl:template>
                </xsl:stylesheet>
    </renderinginstructions>
</notification>


Just to update this: I ended up just dealing with the warning.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜