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

Getting xsl:param out of an XSL document

  • To: xml-dev@l...
  • Subject: Getting xsl:param out of an XSL document
  • From: James Adams <james.xml@v...>
  • Date: Mon, 11 Jul 2005 06:04:32 -0700
  • User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

xsl document param
Many of the modern XSLT processors have a simple way to get parameters 
in and out of a transformation.  An example using PHP and the libxslt 
processor (works pretty much the same way with Java and Xalan):

// Create a new DOM object and load it from an XSL file
$xsl = new DomDocument();
$xsl->load('stylesheet.xsl');

// Create a new DOM object and load it from an XML file
$source = new DomDocument();
$source->load('source.xml');

// Create a new Processor and import the XSL stylesheet
$transform = new XSLTProcessor ();
$transform->importStyleSheet($xsl);

// Set the input parameters (namespace, param-name, value)
$param_input = "TagToMatch";
$transform->setParameter( '', 'param_input', $param_input );

// Transform the document
$result = $transform->transformToDoc($source);

// Retrieve the output parameters
$output = $transform->getParameter( '', 'parameter_output');

Given the above code (or something similar in another language), I am 
then able to use the input parameter value in the XSL, as long as the 
<xsl:param> element is defined as a top-level element:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0"
    xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="xml" indent="yes"/>
    <xsl:param name="param_input"/>
    <xsl:template match="/">
        <xsl:copy-of select="dyn:evaluate($param_input)"/>
    </xsl:template>
</xsl:stylesheet>

Where I run into problems is trying to get a parameter back out of the 
XSL.  I know that there is some method to do this since the parser 
implements a functioning getParameter() method, but how do I create a 
top-level <xsl:param> element and assign it a value somewhere later down 
the parse tree?  This functionality is fairly important to a project I 
am working on, so any help would be greatly appreciated.

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.