0

I'm trying to do some fancy navigational work within a large XML sheet, and am generating links with querystrings in my transformation.

What I would like to do is parse the querystring within my .module file, and then pass it somehow to the XSL processor.

Essentially, right now I have (without any error handling at present):

/* generate hook */
function _xml_import_generate()
{
  $p = $_GET['p'];

  $path = drupal_get_path('module', 'xml_import');

  $xsl = new DOMDocument();
  $xsl->load("{$path}/xml_import.xsl");

  $xslt = new XSLTProcessor();
  $xslt->importStyleSheet($xsl);

  $xml = new DOMDocument();
  $xml->load("feed.xml");

  return (string) $xslt->transformToXML($xml);
}

I can't seem to find any documentation regarding this...but how do I pass $p into my XSL transformation?

2

I think you just need to parse out the query string, and then use XSLTProcessor::setParameter:

/* generate hook */
function _xml_import_generate()
{
  $p = $_GET['p'];

  $path = drupal_get_path('module', 'xml_import');

  $xsl = new DOMDocument();
  $xsl->load("{$path}/xml_import.xsl");

  $xslt = new XSLTProcessor();
  $xslt->importStyleSheet($xsl);

  $xslt->setParameter("", "p", $p);

  $xml = new DOMDocument();
  $xml->load("feed.xml");

  return (string) $xslt->transformToXML($xml);
}

Your parameter should then appears as a <xsl:param /> in your XSLT.

  • so in my XSLT i should be able to pull it out by <xsl:param name="p" select="$p" />? – the_e Jul 9 '12 at 14:56
  • My recollection of parameters is really hazy, but IIRC, you use it as <xsl:value-of select="$p" /> wherever you need it. – mpdonadio Jul 9 '12 at 15:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.