If I use <xsl:param> without specifying a value, the transformer assumes that the value is an empty string.
In other words, if I forgot to specify a value (e.g. <xsl:param name="N"/>), the compiler doesn’t signal an error. This may cause my program to fail silently, which is a bad thing.
How can I specify that my <xsl:param> must have an explicit value? For example, this code should give me an error because there is no explicit value specified:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:call-template name="F1"></xsl:call-template>
<html>
<head>
<title></title>
</head>
<body>stuff</body>
</html>
</xsl:template>
<xsl:template name="F1">
<xsl:param name="N"/> <!-- I Should Get An Error Here! -->
</xsl:template>
</xsl:stylesheet>
Am looking for a solution in both XSLT 1.0 and XSLT 2.0.
You could actually do this with a bit of meta-XSLT:
This stylesheet takes any stylesheet as an input, and checks that all call-template’s have the right parameters, outputting a message if there’s any errors.
This obviously isn’t going to put the error checking in the transformer itself, but it will list ALL errors in one go, and can potentially be extended to check for other issues as well.
EDIT: I’ve adapted it to handle optional parameters, and added in a means of describing where the error is; it’s actually a bit of a redesign, with optional parameters simply counting them was going to be tricky, so I removed that bit. Every error is itemized anyway, so the count wasn’t really necessary.