[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Schema validation on a function parameter

Subject: Re: Schema validation on a function parameter
From: "Matthieu RICAUD-DUSSARGET m.ricaud-dussarget@xxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 12 Feb 2018 17:52:01 -0000
Re:  Schema validation on a function parameter
Thank you Michael,

With the copy and the function this will be quite transparent to the
developers, meaning it's quite easy to validate params of a function.

First time I need this actualy, but I'll consider moving this to a common
function in our lib.

Regards,
Matthieu


-----Message d'origine-----
De : Michael Kay mike@xxxxxxxxxxxx
[mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx]
Envoyi : lundi 12 fivrier 2018 18:19
@ : xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Objet : Re:  Schema validation on a function parameter

You can simplify it a little to

<xsl:function name="my:function">
   <xsl:param name="e" as="element()"/>
   <xsl:variable name="e" as="schema-element(my:element)">
       <xsl:copy-of select="$e" validation="strict"/>
   </xsl:variable>
   ... do something here
 </xsl:function>

If you do this a lot you could also try

<xsl:function name="my:validate" as="element(*, xs:anyType)">
  <xsl:param name="e" as="element()"/>
   <xsl:variable name="e" as="schema-element(*, xs:anyType)">
       <xsl:copy-of select="$e" validation="strict"/>
   </xsl:variable>
</xsl:function>

<xsl:function name="my:function">
   <xsl:param name="e" as="element()"/>
   ... do something here with my:validate($e)  </xsl:function>

Michael Kay
Saxonica


> On 12 Feb 2018, at 12:07, Matthieu RICAUD-DUSSARGET
m.ricaud-dussarget@xxxxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.