Use the XSLTProcessor::setParameter( ) method: The first argument is the namespace and can be null
$uid = '123'; $dom = new DOMDocument $dom->load('addresses.xml'); $xsl = new DOMDocument $xsl->load('stylesheet.xsl'); $xslt = new XSLTProcessor(); $xslt->importStylesheet($xsl); $xslt->setParameter(NULL, 'user_id', $uid); print $xslt->transformToXML($dom);
stylesheet.xsl:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/addresses/person">
<xsl:if test="userid=$user_id">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>