Ver um Único Post

 
  #3 (permalink)  
Antigo 15/12/2009
Avatar de LuizVaz
LuizVaz LuizVaz está offline
Administrator
Super Admin
Points: 10,505, Level: 68 Points: 10,505, Level: 68 Points: 10,505, Level: 68
Activity: 0% Activity: 0% Activity: 0%
Last Achievements
 
Registrado em: Oct 2009
Localização: Belo Horizonte
Posts: 86
Thanks: 2
Thanked 6 Times in 6 Posts
Activity Longevity
0/20 20/20
Today Posts
sssssss86
Enviar mensagem via Windows Live Messenger para LuizVaz Enviar mensagem via Yahoo para LuizVaz
Thumbs up

Pessoal,

com o código abaixo consegui aplicar o XSL dinamicamente no XML usando PHP.
São menos de 50 linhas de código.
O resto está todo no XML e XSL.

Código:
  # print.php?u=$1&n=$2&v=$3
  # u = CNPJ
  # n = NF (ANO/NOTA)
  # v = Verificador
  # File Path CNPJ/ANO/NOTA-Verificador.xml

  $d = dirname(__FILE__);
  $u = $y = $s = $v = '';

  if(!empty($_GET['u'])){
    $u = $_GET['u'];
  }
  if(!empty($_GET['n'])){
    $y = substr($_GET['n'], 0, 4)+0;
    $s = substr($_GET['n'], 4)+0;
  }
  if(!empty($_GET['v'])){
    $v = strtolower($_GET['v']);
  }

  $f = "$d/$u/$y/$s-$v.xml";
  $x = "$d/$u/nfse.xsl";

  if (file_exists($f)){
      // Carrega o XML e o XSL
      $xml = new DOMDocument;
      $xml->load($f);
      $xsl = new DOMDocument;
      $xsl->load($x);

      // Configura o transformer
      $proc = new XSLTProcessor;
      $proc->importStyleSheet($xsl);

      // Aplica o StyleSheet
      $html  = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'."\n";
      $html .= $proc->transformToXML($xml);
      $html  = str_replace('<?xml version="1.0"?>', '', $html);
      print $html;
  }
  else{
      print "Nota Fiscal Inexistente!";
  }

Lembrando que, o arquivo XML da NFSe está com Encoding UTF-8.
Isso está errado, pois a NFSe vem com caracteres ISO-8859-1 no corpo.
Portanto, façam a troca de UTF-8 para ISO-8859-1 antes chamarem as funções no PHP.
Caso contrário, receberão alguns warnings na execução.

Abaixo um Link de exemplo:
:: NFS-e - Nota Fiscal de Serviços eletrônica ::

Att,
Luiz Vaz
Responder com Citação
 

Content Relevant URLs by vBSEO 3.3.0