0

I am getting an empty result when trying to pass a parameter to my stylsheet using the php xslt processor. Any ideas would be greatly appreciated!

PHP:

<?php 
$xsl = new DomDocument();
$xsl->load("style_listgastro.xsl");
$inputdom = new DomDocument();
$inputdom->load("XXX");
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
$xsl = $proc->setParameter(null, 'k', $_GET['k']);
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
?>

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:td="urn:schemas-XXX:Relationen">
<xsl:param name="k" />
<xsl:template match="/td:Relationen">
...
<xsl:apply-templates select="td:Benutzer_zu_Gastro">
<xsl:sort select="td:Gastroname"></xsl:sort>
</xsl:apply-templates>
...
</xsl:template>
<xsl:template match="td:Benutzer_zu_Gastro">
<xsl:if test="td:Kategorien = '{$k}'">
<li><a>
<xsl:attribute name="href">XXX</xsl:value-of>
</xsl:attribute>
<xsl:value-of select="td:Gastroname"></xsl:value-of>
</a></li>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

2 Answers 2

2

This line is incorrect:

<xsl:if test="td:Kategorien = '{$k}'">

it's not comparing td:Kategorien against the value of $k, but against the string value {$k} (and I'm guessing that td:Kategorien will never have the value {$k}). Instead, just use this:

<xsl:if test="td:Kategorien = $k">


Or, a better fix would be to change the apply-templates line to this:

<xsl:apply-templates select="td:Benutzer_zu_Gastro[td:Kategorien = $k]">

and remove the xsl:if altogether.

Sign up to request clarification or add additional context in comments.

Comments

0

Try using '' instead of null as the first argument for setParameter()?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.