是否有类似的内容?

时间:2021-07-22 21:31:50

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 个解决方案

#1


1  

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

没有;通常,XSL引擎不依赖于Web服务器。

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.

但是,大多数XSL引擎允许您传递一些参数以及样式表和文档,因此如果您从支持Web的系统调用它,您可以将GET参数直接映射到XSL引擎。

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

例如,如果您使用的是PHP,则可以执行以下操作:

<?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>

#1


1  

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

没有;通常,XSL引擎不依赖于Web服务器。

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.

但是,大多数XSL引擎允许您传递一些参数以及样式表和文档,因此如果您从支持Web的系统调用它,您可以将GET参数直接映射到XSL引擎。

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

例如,如果您使用的是PHP,则可以执行以下操作:

<?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>