What are the best practices for handling character encoding issues when using XSLTProcessor in PHP?

Character encoding issues can arise when using XSLTProcessor in PHP, especially when dealing with different character sets or encodings. To handle these issues, it is recommended to set the input and output encoding explicitly in the XSLTProcessor object using the `importStylesheet` method. This ensures that the input XML and XSL files are parsed correctly and the output is generated with the desired encoding.

$xslFile = 'stylesheet.xsl';
$xmlFile = 'data.xml';

$xslt = new XSLTProcessor();
$dom = new DomDocument();
$dom->load($xslFile);
$xslt->importStylesheet($dom);
$xslt->setParameter('', 'encoding', 'UTF-8'); // Set the output encoding

$xml = new DomDocument();
$xml->load($xmlFile);
$output = $xslt->transformToXML($xml);

echo $output;