Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XSLT->;XHTML:内联PHP?_Php_Xslt - Fatal编程技术网

XSLT->;XHTML:内联PHP?

XSLT->;XHTML:内联PHP?,php,xslt,Php,Xslt,我试图使用XSLT生成一些带有内联PHP的XHTML。我遇到了在属性中生成内联PHP的问题 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/1999/xhtml" version="1.0"> <xsl:output method="xml" indent="yes" doctype-system="h

我试图使用XSLT生成一些带有内联PHP的XHTML。我遇到了在属性中生成内联PHP的问题

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:html="http://www.w3.org/1999/xhtml" version="1.0">
  <xsl:output method="xml"
       indent="yes"
       doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
       doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
       omit-xml-declaration="yes" />

  <xsl:template match="/">
    <html lang="<?php echo getLang(); ?>" xml:lang="<?php echo getLang(); ?>">
      <head>
 <xsl:processing-instruction name="php">include_title();</xsl:processing-instruction>

(Much more code ...)


?php

?php

可能使用与此相同的指令:

<xsl:processing-instruction name="php">include_title();</xsl:processing-instruction>
include_title();

可能使用与此相同的指令:

<xsl:processing-instruction name="php">include_title();</xsl:processing-instruction>
include_title();

如果您只是回显getLang(),它实际上返回了什么吗?您的代码和环境描述非常有限,因此很难说什么是作为PHP处理的,什么是由XSLT处理器处理的

如果将
替换为

如果您只是回显getLang(),它实际上返回了什么吗?您的代码和环境描述非常有限,因此很难说什么是作为PHP处理的,什么是由XSLT处理器处理的

如果将
替换为

您可以选择使用XSLT2.0吗?如果你这样做,你可以使用。像这样:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:html="http://www.w3.org/1999/xhtml" version="2.0">
  <xsl:output method="xml"
       indent="yes"
       doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
       doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
       omit-xml-declaration="yes" 
       use-character-maps="php"/>

  <xsl:character-map name="php">
    <xsl:output-character character="«" string="&lt;"/>   
    <xsl:output-character character="»" string="&gt;"/>
  </xsl:character-map>

  <xsl:template match="/">
    <html lang="«?php echo getLang(); ?»" xml:lang="«?php echo getLang(); ?»">
      <head>
        <xsl:processing-instruction name="php">include_title();</xsl:processing-instruction>
      </head>
    </html>
  </xsl:template>
</xsl:stylesheet>

包括标题();

您可以选择使用XSLT2.0吗?如果你这样做,你可以使用。像这样:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:html="http://www.w3.org/1999/xhtml" version="2.0">
  <xsl:output method="xml"
       indent="yes"
       doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
       doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
       omit-xml-declaration="yes" 
       use-character-maps="php"/>

  <xsl:character-map name="php">
    <xsl:output-character character="«" string="&lt;"/>   
    <xsl:output-character character="»" string="&gt;"/>
  </xsl:character-map>

  <xsl:template match="/">
    <html lang="«?php echo getLang(); ?»" xml:lang="«?php echo getLang(); ?»">
      <head>
        <xsl:processing-instruction name="php">include_title();</xsl:processing-instruction>
      </head>
    </html>
  </xsl:template>
</xsl:stylesheet>

包括标题();


这只会给出以下结果:lang=“?php echo getLang();?”抱歉,请重试。这只会给出以下结果:lang=“?php echo getLang();?”抱歉,请重试。这是一个有趣的想法。当我尝试这样做时,我得到了错误消息:“unscaped”如果您需要更多信息,请询问。我没有包括所有代码和环境信息,因为这似乎是多余的。有趣的想法。当我尝试这样做时,我得到错误消息:“unscaped”如果您需要更多信息,请询问。我没有包括所有的代码和环境信息,因为这似乎是多余的。我喜欢你的想法。这可能是解决方案,但我无法测试它。我使用的是PHP5 XSL模块,它使用libxslt版本1.1.22。据我所知,它只支持XSLT1.0:(XSLT 1.0规范不允许禁用属性值的输出转义。我想没有办法让XSLT 1.0在属性值中输出未转义的尖括号。也许可以添加一个“字符映射”样式XSLT转换后的后处理阶段?在昨天阅读了您的建议后,这正是我使用str_replace()PHP函数所做的。我更喜欢一个不太“凌乱”的解决方案,但这暂时有效。我喜欢你的想法。这可能是解决方案,但我无法测试它。我正在使用PHP5 XSL模块,它使用libxslt版本1.1.22。据我所知,它只支持XSLT1.0(XSLT 1.0规范不允许禁用属性值的输出转义。我想没有办法让XSLT 1.0在属性值中输出未转义的尖括号。也许可以添加一个“字符映射”样式XSLT转换后的后处理阶段?在昨天阅读了您的建议后,这正是我使用str_replace()PHP函数所做的。我更喜欢一个不太“凌乱”的解决方案,但这在目前是有效的。重点是:您希望从
getLang()返回值
在转换过程中被集成到转换结果中,而您希望
被直接包含在转换输出中?还是希望转换输出将PHP指令
直接包含在属性中?我希望XSLT输出给出底部的PHP脚本在属性中使用。这样就可以保留网页的动态特性。关键是:您需要
getLang()中的返回值
在转换过程中被集成到转换结果中,而您希望
被直接包含在转换输出中?还是希望转换输出将PHP指令
直接包含在属性中?我希望XSLT输出给出底部的PHP脚本在属性中包含字面意义上的。这样可以保留网页的动态特性。