Re: [xsl] passing several external arguments to the spreadsheet

Subject: Re: [xsl] passing several external arguments to the spreadsheet
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 02 Sep 2009 10:33:09 -0400
Hi,

Another alternative is to use an external configuration file to store the list of languages as an XML document, and call that in from your main stylesheet using the document() function.

This is probably easier if your list of languages becomes long and/or you need to control it in some way (for example, validating it against a list of known languages).

Using a runtime parameter may be easier if you need control dynamically at runtime, you don't need the list to persist between runs, and your list is short.

The two approaches can also be combined. For example, your external list can control what languages are allowed, while the runtime parameter gives those that will actually be used (values in the parameter that don't appear in the external list can be ignored).

Finally, note that tokenize() is not available in unextended XSLT 1.0. If you can't use XSLT 2.0 or a 1.0 extension function you'll need to work around this limitation.

Cheers,
Wendell

At 10:21 AM 9/2/2009, you wrote:
Manuel Souto Pico wrote:

Is it possible to run something like that using the param option (or, even better, to do it in the editor)? (in capitals for clarity)
$ java -jar path/to/saxon9.jar LANG=en,fr,pt input.xml spreadsheet.xsl > output.xml
I guess it must be something like that, but then, how do I get those 3 or n parameters into the spreadsheet? If it was only one parameter i would get it with
<xsl:param name="lang"/>
but as there are more than one, I guess I should put them in a kind of array and then do a for-each?

I think you should be able to pass in a string value as the parameter and then use the tokenize function to split it up into a sequence of lang values e.g.
<xsl:param name="lang"/>
<xsl:variable name="languages" select="tokenize($lang, ',')"/>


  <xsl:template match="xliff">
    <xsl:copy>
      <xsl:variable name="file" select="file"/>
      <xsl:for-each select="$languages">
        <xsl:apply-templates select="$file">
          <xsl:with-param name="lang" select="."/>
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="file">
    <xsl:param name="lang"/>
    <xsl:copy>
      <xsl:attribute name="lang" select="$lang"/>
      <xsl:copy-of select="node()"/>
    </xsl:copy>
  </xsl:template>


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread