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