views:

693

answers:

2

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

+1  A: 

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"&gt;
  <!-- 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>
digitala
A: 

on ASP.NET you can use this library: http://myxsl.net/ and use XSLT to write web pages...

<xsl:stylesheet ...  xmlns:myxsl="http://myxsl.net/"&gt;

  <xsl:param name="color" as="xs:string" myxsl:bind="query"/>
  <xsl:param name="number" as="xs:integer" myxsl:bind="query"/>

  <xsl:template name="main">
    I like the color <xsl:value-of select="$color" />
    and the number <xsl:value-of select="$number" />.
  </xsl:template>

</xsl:stylesheet>

Notice $number is an integer.

Max Toro