سؤال

إذا كان إرسال هذا الطلب إلى الصفحة:

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

أستطيع أن أفعل شيئا من هذا القبيل؟:

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

إذا كنت بحاجة إلى توضيح السؤال يمي أعلم

شكرا على أي إجابات ،

Chrelad

هل كانت مفيدة؟

المحلول

لا ؛ في عام ، XSL محركات ليست مرتبطة إلى ملقم ويب.

ومع ذلك ، فإن معظم XSL محركات تسمح لك لتمرير بعض المعلمات جنبا إلى جنب مع الأنماط الخاصة بك وتوثيق ذلك ما كنت يمكن هل إذا كنت تتصل من تمكين شبكة الإنترنت هو الخريطة الخاصة بك الحصول على المعلمات مباشرة إلى الخاص بك XSL المحرك.

على سبيل المثال, إذا كنت تستخدم 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);

سيكون لديك للتأكد من تطهير أي شيء يمكنك تمرير من خلال.ثم يمكنك أن تفعل ببساطة:

<?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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top