OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Getting xsl:param out of an XSL document

[ Lists Home | Date Index | Thread Index ]
  • To: xml-dev@lists.xml.org
  • Subject: Getting xsl:param out of an XSL document
  • From: James Adams <james.xml@viascape.com>
  • Date: Mon, 11 Jul 2005 06:04:32 -0700
  • User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

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.




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS