XSLT ->

4 Cevap php

Ben inline PHP ile bazı XHMTL oluşturmak için XSLT kullanmaya çalışıyorum. Ben inline PHP özniteliklerde üreten bir sorun üzerinden çalıştırmak.

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

aşağıdaki sonuçları verir:

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

Html elemanın nitelikleri boş: "lang" ve "lang xml" olduğuna dikkat çekmek! Yani açıkça, bu satır içi PHP işlemek için yanlış bir yoldur.

Yani herkes istenilen sonuç aşağıda gösterilen almak için xsl kodunu değiştirmek için nasıl biliyor?

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

Teşekkürler, Kevin

4 Cevap

Eğer XSLT 2.0 kullanma seçeneği var mı? Bunu yaparsanız, size kullanabileceğiniz character maps. Bu gibi:

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

<? php ... >

belki bu için kullanılan aynı direktifi kullanılarak:

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

?

Sadece getLang echo (), aslında bir şey mi dönüyor? Sizin kod ve çevre açıklama çok sınırlı, bu yüzden PHP gibi işlenmiş oluyor ne söylemek zor, ve bir XSLT işlemci tarafından işlenir ne oluyor.

What happens if you replace <?php echo getLang();?> with <?php echo '<?php echo getLang();?>' ;?>