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

what's the best way to validate input parameters to a

Subject: 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 21:57:38 -0000
 what's the best way to validate input parameters to a
Hello! I've 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"
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> isn't allowed at the top level of a stylesheet.

So for now I'm doing this in a "dummy" root element template that doesn't 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 there's probably a better way. Is there?

-----
Chris Papademetrious
Tech Writer, Implementation Group
(610) 628-9718 home office
(570) 460-6078 cell

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.