External Parameters

1. Combining parameters
2. Xalan external Parameters
3. Dynamic pages with URL parameters

1.

Combining parameters

Steve Muench


Here's a couple of ways you can do this...

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

  <xsl:param name="key">12345</xsl:param> <!-- Test value -->

  <!-- Technique 1, Using <xsl:text> and <xsl:value-of> -->
  <xsl:param name="url">
    <xsl:text>http://localhost:8000/servlet/servletName?objectKey=</xsl:text>
    <xsl:value-of select="$key"/>
  </xsl:param>

  <!-- Technique 2, Use concat() function. -->
  <xsl:param name="url2"
     select="concat('http://localhost:8000/servlet/servletName',
                    '?objectKey=', $key)" />

  <xsl:template match="/">
    <xsl:value-of select="$url"/>
    <xsl:text>
</xsl:text>
    <xsl:value-of select="$url2"/>
  </xsl:template>

</xsl:stylesheet>

If I try this from the command-line with Oracle XSLT,
passing a value for the parameter, I get:

$ oraxsl -p key='9988' data.xml test.xsl

http://localhost:8000/servlet/servletName?objectKey=9988
http://localhost:8000/servlet/servletName?objectKey=9988


2.

Xalan external Parameters

Scott_Boag

For Xalan, the value passed is an expression, so use -param person "'Some String'" to pass a simple string.

3.

Dynamic pages with URL parameters

Eric van der Vlist, Bill Humphries

You'll find 2 examples (developed for XT in servlet mode) at 4xt and an introduction about XSLT in servlet mode in the archives.

VB Script, dynamic pages with URL parameters

I'm understanding that you want to pass a parameter into a style sheet from some calling script/shell/process and then use that parameter in a template that generates the URL?

So you have a stylesheet like:

<xsl:stylesheet ... >
  <xsl:output method="html"/>
  <xsl:parameter name="URLPARM"/>
  
  <xsl:variable name="BASE">http://www.foo.com/dynamic.cgi?</xsl:variable>
  <xsl:variable name="URL" select="concat($BASE,$URLPARM)"/> 

  <xsl:template match="/">
    <html>
	<head>
	   <title>example</title>
	</head>
	<body>
	  <a href="{$URL}">dynamic link</a>
	</body>
    </html>
  </xsl:template>

</xsl:stylesheet>

What platform are you writing this in? I've got working examples in PHP and ASP of how to pass parameters into a styleheet. You can then use the parameter to generate the URL.

PHP: http://www.whump.com/www/phpSablot.html (Wrapper Class for PHP Sablotron XSLT Engine Extension) See the notes on the setParameter method.

ASP:

You'll need to make sure you have the May or later release of the parser.

You can't use the transformNode method of the DOM, instead, you need to create a XSLTemplate object, get an XSLTProcessor object from it, then use the addParameter method.

<%@LANGUAGE="VBScript"%>

<%
Dim xsldoc
Dim myTemplate
Dim myProc
Dim xmldoc

'It has to be Free-Threaded, the idea is to make the widget available
'to an app and have multple users bang on it.
Set xsldoc = Server.CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
xsldoc.async = false
xsldoc.load Server.MapPath("tranform.xsl")

'This is the critical widget, a compliled XSL template
Set myTemplate = Server.CreateObject("Msxml2.XSLTemplate.3.0")
myTemplate.stylesheet = xsldoc

Set xmldoc = Server.CreateObject("Msxml2.DOMDocument.3.0")

xmldoc.async = false
xmldoc.load Server.MapPath("input.xml")

Set myProc = myTemplate.createProcessor()
myProc.input = xmldoc

'Now set the parameter
myProc.addParameter(URLPARM,"somestring")
myProc.output = Response
myProc.transform()

%>