stylesheet parameters

Parameters

1. Stylesheet parameters
2. Top level parameter defaults
3. passing parameters with spaces to a stylesheet

1.

Stylesheet parameters

Scott Boag



<?xml version="1.0"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version
="1.0">

  <xsl:param 
  name="testing">#Default Error String</xsl:param>

  <xsl:template match="/">
    <out>
    <xsl:apply-templates>
      <xsl:with-param name="foo" select="$testing"/>
    </xsl:apply-templates>
    </out>
  </xsl:template>

  <xsl:template match="someelement">
    <xsl:param name="foo"/>
    <xsl:value-of select="$foo"/>
  </xsl:template>

</xsl:stylesheet>

You can access $testing from foo directly also.  This was
tested on the command line with -param testing "'testing
val'".  The output on my build was:

<?xml version="1.0" encoding="UTF-8"?>
<out>testing val</out>

   

2.

Top level parameter defaults

Wendell Piez



Setting the parameter default as

<xsl:param name="x" select="false()"/>

The value of $x is a Boolean false (XPath 4.3). Then the test

<xsl:if test="$x"> ... </xsl:if>

will fail unless the default is overridden by a parameter
passed in.

3.

passing parameters with spaces to a stylesheet

Mike Kay



> Can anyone tell me how to pass parameters with spaces in the value
> to a stylesheet via the command line. 


I don't know of any way of doing it. Certainly there's
nothing in Saxon to enable it. The Java documentation is
remarkably vague about the syntax of the command line, and I
don't know whether it depends on which shell you're
using. When will the industry come up with a decent job
control language?

If no-one comes up with anything, you'll have to pass the
thing in with an underscore or such like, and use
translate() within the stylesheet to change it.