[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Schema validation on a function parameter
Hi ! I have a function which takes an element as parameter. I want to validate this element against an xsd schema type definition. I'm using XSLT 3.0 with a schema aware processor (SaxonEE 9.7.0.15) At first, I thought I only have to : <xsl:import-schema schema-location="my-schema.xsd"/> And then type the parameter: <xsl:param name="e" as=" schema-element(my:element)"/> But it does not validate (when the xml in not valid I don't get any errors or warnings) Then after reading the XSLT 3.0 spec, I realized validation is processed only on source or result-tree: "The imported type definitions can be used for temporary nodes or for nodes on a result tree just as much as for nodes in source documents" So I found this solution : <xsl:import-schema schema-location="my-schema.xsd"/> <xsl:function name="my:function"> <xsl:param name="e" as="element()"/> <xsl:variable name="e" as="document-node(schema-element(my:element))"> <xsl:document validation="strict"> <xsl:sequence select="$e"/> </xsl:document> </xsl:variable> ... do something here </xsl:function> This works pretty well, I actualy get a fatal error with its description when $e is not valid, which is exactly what I was looking for. Any advices, comment on this, is it a good way to do ? or there is something more obvious which I missed (preventing creating this document-node for example?) Thanks in advance, Cheers Matthieu
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|