Subject: Re: [xsl] what's the best way to validate input parameters to a stylesheet? From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 19 Mar 2021 22:37:48 -0000 |
I couldnbt use a qualifier on / itself: /[b&] But I was able to use one on the root element: /*[b&] and that is fine too. p From: Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Friday, March 19, 2021 6:30 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] what's the best way to validate input parameters to a stylesheet? Hey, I really like that! Although I think Ibll use $valid-args, then use a b/not($valid-args)b match. Thank you!! * Chris From: Wendell Piez wapiez@xxxxxxxxxxxxxxx<mailto:wapiez@xxxxxxxxxxxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx rytech.com>> Sent: Friday, March 19, 2021 6:08 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Subject: Re: [xsl] what's the best way to validate input parameters to a stylesheet? Hey Chris, You could pull the logic into a static variable: <xsl:variable name="doc-fails" as="xs:boolean" select="matches($from.att, '^@\w+=\w+$') and matches($to.att, '^@\w+=\w+$')"/> then <xsl:template match="/[$doc-fails]"> ... this document fails ... </xsl:template> Make the @priority explicit if you want to give a better hint. It's really factoring out the choose into a template match in the normal way. You could even do it without the variable for maximum mystery. Cheers, Wendell On Fri, Mar 19, 2021 at 5:58 PM Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx<mailto:christopher.papademetrious@syn opsys.com> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx<mailto:xsl-list-service@xxxxxxxxxxxx rytech.com>> wrote: Hello! Ibve got a stylesheet that takes two string parameters: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform<https://urldefense.com/v3/__h ttp:/www.w3.org/1999/XSL/Transform__;!!A4F2R9G_pg!MQ0PKGJ8iTMGj8nbezhr8RahBDE Lg2Lr11DA9cfXfWGlSiD8o6YQvglkeOzZWFJDzoAE_zHtMvO5XdQ$>" version="2.0"> <xsl:param name="from.att" as="xs:string"/> <xsl:param name="to.att" as="xs:string"/> Both parameters are expected to be strings in the form of @attributename=value At first I tried adding a check at the top level of the stylesheet: <xsl:if test="not(matches($from.att, '^@\w+=\w+$') and matches($to.att, '^@\w+=\w+$'))"> <xsl:message terminate="yes">Input parameters must be in the form '@attributename=value'.</xsl:message> </xsl:if> but <xsl:if> isnbt allowed at the top level of a stylesheet. So for now Ibm doing this in a bdummyb root element template that doesnbt do anything: <!-- this doesn't actually do anything other than validate our input parameters --> <xsl:template match="/" priority="20"> <xsl:choose> <xsl:when test="matches($from.att, '^@\w+=\w+$') and matches($to.att, '^@\w+=\w+$')"> <xsl:next-match/> </xsl:when> <xsl:otherwise> <xsl:message>Input parameters must be in the form '@attributename=value'.</xsl:message> <xsl:copy-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:template> but I feel like therebs probably a better way. Is there? ----- Chris Papademetrious Tech Writer, Implementation Group (610) 628-9718 home office (570) 460-6078 cell XSL-List info and archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__ ;!!A4F2R9G_pg!MQ0PKGJ8iTMGj8nbezhr8RahBDELg2Lr11DA9cfXfWGlSiD8o6YQvglkeOzZWFJ DzoAE_zHt_aVxtns$> EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu b/xsl-list/174322__;!!A4F2R9G_pg!MQ0PKGJ8iTMGj8nbezhr8RahBDELg2Lr11DA9cfXfWGl SiD8o6YQvglkeOzZWFJDzoAE_zHtQNVPHFI$> (by email) -- ...Wendell Piez... ...wendell -at- nist -dot- gov... ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org... ...github.com/wendellpiez.<https://urldefense.com/v3/__http:/github.com/wende llpiez.__;!!A4F2R9G_pg!MQ0PKGJ8iTMGj8nbezhr8RahBDELg2Lr11DA9cfXfWGlSiD8o6YQvg lkeOzZWFJDzoAE_zHt06EYrl8$>.. ...gitlab.coko.foundation/wendell... XSL-List info and archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__ ;!!A4F2R9G_pg!MQ0PKGJ8iTMGj8nbezhr8RahBDELg2Lr11DA9cfXfWGlSiD8o6YQvglkeOzZWFJ DzoAE_zHt_aVxtns$> EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu b/xsl-list/3380743__;!!A4F2R9G_pg!MQ0PKGJ8iTMGj8nbezhr8RahBDELg2Lr11DA9cfXfWG lSiD8o6YQvglkeOzZWFJDzoAE_zHtVZmkIhU$> (by email) XSL-List info and archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__ ;!!A4F2R9G_pg!IcZRXkNFp8OoBHVU7755hMl6EWNm08r1mau7bLKzb6UiWOjsO45Vt4MHRn70CBb U2vHvJdQuzOuV5B4$> EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu b/xsl-list/3380743__;!!A4F2R9G_pg!IcZRXkNFp8OoBHVU7755hMl6EWNm08r1mau7bLKzb6U iWOjsO45Vt4MHRn70CBbU2vHvJdQuBREAuVM$> (by email<>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] what's the best way to va, Chris Papademetrious | Thread | [xsl] messing about with XSLT, Chris Papademetrious |
Re: [xsl] what's the best way to va, Chris Papademetrious | Date | [xsl] messing about with XSLT, Chris Papademetrious |
Month |