Question

If I send this request to a page:

http://www.server.com/show.xml?color=red&number=two

Can I do something like this?:

I like the color <xsl:url-param name="color" /> and the number <xsl:url-param name="number" />.

If you need clarification of the question, lemme know

Thanks for any answers,

Chrelad

Was it helpful?

Solution

No; in general, XSL engines aren't tied to a web server.

However, most XSL engines allow you to pass in some parameters along with your stylesheet and document so what you can do, if you're calling it from a web-enabled system, is map your GET parameters directly through to your XSL engine.

For instance, if you were using PHP, you could do something like this:

<?php

$params = array(
    'color' => $_GET['color'],
    'number' => $_GET['number']
);

$xsl = new DOMDocument;
$xsl->load('mystylesheet.xsl');

$xml = new DOMDocument;
$xml->load('mydocument.xml');

$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules

foreach ($params as $key => $val)
    $proc->setParameter('', $key, $val);

echo $proc->transformToXML($xml);

You'd have to make sure you sanitize anything you passed-through. Then, you can simply do:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Remember to pick-up the parameters from the engine -->
  <xsl:param name="color" />
  <xsl:param name="number" />
  <xsl:template match="*">
    I like the color <xsl:value-of select="$color" /> 
    and the number <xsl:value-of select="$number" />.
  </xsl:template>
</xsl:stylesheet>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top