I have an XML file that is “well formed and valid” (matched with an XSD schema, tested at http://xsdvalidation.utilities-online.info/).
I am using these lines of code in the XSD to restrict the XML input of a <firstname>:
<xsd:pattern value = "[A-Z][a-z]+" />
<xsd:minLength value = "2" />
<xsd:maxLength value = "25" />
So, the website mentioned above will throw an error and not validate when the <firstname> does not match this regex and length restrictions (say, if I enter “5” as the first name in the XML file).
But, when I open the XML file into Firefox (parsed into HTML with an XSL file), it does not throw an error and will display whatever is entered into the XML file regardless of the regular expression and length restrictions.
Are XSD schemas not meant to be used in this way, to error check in web browsers? Do I need to use the restrictions in the XSLT instead of the XSD?
XPath 2.0 (and XSLT 2.0) is a strongly-typed language,where all built-in and user-defined schema types can be validated.
One can use an XSLT 2.0 SA (Schema- oriented) processor to enforce schema type validation of:
A source XML document.
The value of any parameter passed to a template/(xsl:)function or (externally) to the stylesheet.
The value of any
xsl:variable.The result produced by any template or xsl:function
Using these features properly makes unnecessary any post-transformation validation of the transformation result.