doudun8705 2015-05-26 10:45
浏览 74

将PHP变量作为参数传递给XSL

I have a PHP page that outputs XML by changing the header type and outputting the xml with an XSL stylesheet for an RSS feed:

<?php
header('Content-Type: text/xml; charset=utf-8');
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
";
echo '<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/path/feed.xsl"?>' . "
";
?>
<channel>
    <item>...</item>...
</channel>

I want to pass some PHP variables from the original page to the XSL, how do I do this?

Example: I have the variables...

$header = "This is a cool page";
$description = "This is a description";

...that I want to pass to the XSL page and use within it meaning the title can be changed through PHP and dynamically changed in the XSL rather than hard coding it.

It cannot be passed through XML because I am using the XSL as a fallback and therefore the title should not be displayed when the browser supports RSS. Also it must come from that page rather than referencing another file with that variable.

Something like

<?xml-stylesheet title="XSL_formatting" type="text/xsl" param-header="<?=$header?>' param-description="<?=$description?>' href="/path/feed.xsl"?>

Let me know if there is a better way to achieve this.

  • 写回答

1条回答 默认 最新

  • dqwmhrxt68679 2015-05-26 15:51
    关注

    *UPDATE - This doesn't work because the extra tags don't validate because they aren't part of a namespace.


    Actually forgot to put the rss tags into the question but when I added XML to store the PHP variables between the rss and channel tags, I could use them in the XSL file dynamically and the XML used to store them doesn't render when viewed in an RSS reader, e.g.

    <rss>
        <extraInfo>
            <heading>...</heading>
            <description>...</description>
        </extraInfo>
        <channel>
            ...
        </channel>
    </rss>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口