There is a XML from that I am constructing an another XML using XSLT. I want some fields to have Hashed Value rather than actual value. Meaning I should know when data is changed but I don't want to know the data due to some security reasons.
<xsl:template name="sensitiveDataTemplate">
<xsl:param name="sensitiveData"></xsl:param>
<xsl:if test="$sensitiveData!=''">
<xsl:value-of select="'XXXXXX'"></xsl:value-of>
</xsl:if>
</xsl:template>
For now I am just replacing data with XXXXX but I need some hashed value here.
For generating the hash value you may register the custom functions.
Refer to the official documentation on how to register custom php function in xlst processor.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
<xsl:template name="sensitiveDataTemplate">
<xsl:param name="sensitiveData"></xsl:param>
<xsl:if test="$sensitiveData!=''">
<xsl:value-of select="'php:some_hash_fun()'"></xsl:value-of>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
function some_hash_fun( )
{
return "XXXX"; // hash value
}
$xmldoc = DOMDocument::loadXML($xml);
$xsldoc = DOMDocument::loadXML($xsl);
$proc = new XSLTProcessor();
$proc->registerPHPFunctions(); // can be either a string (a function name) or an array of functions.
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With