dsfsdf7852 2009-11-19 20:53 采纳率: 100%
浏览 40
已采纳

XSLT - > XHTML:内联PHP?

I'm trying to use XSLT to generate some XHMTL with inline PHP. I've run across a problem with generating inline PHP in attributes.

<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 ...)

gives the following results:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:html="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <?php include_title();?>

(Much more code ...)

Take note that the "lang" and "xml:lang" attributes of the html element are empty! So clearly, this is the wrong way to process inline PHP.

So does anyone know how to change the xsl code to get the desired result shown below?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:html="http://www.w3.org/1999/xhtml" lang="<?php echo getLang(); ?>" xml:lang="<?php echo getLang(); ?>">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <?php include_title();?>

    (Much more code ...)

Thanks, Kevin

  • 写回答

4条回答 默认 最新

  • dtvhqlc57127 2009-11-19 23:20
    关注

    Do you have the option of using XSLT 2.0? If you do, you can use character maps. Like this:

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题