I have this problem with xsl
if I entered the state and the city is working fine ,but if I miss one or the other doesnt work
Thanks

<?php
$city=$_GET['city'];
$state=$_GET['state'];
$dom = new DOMDocument;
$dom->load('Sample.xml');
$xsl = new DOMDocument;
$xsl->load('asn6.xsl');
$xslt = new XSLTProcessor();
$xslt->importStylesheet($xsl);
if(isset($city))
$xslt->setParameter(NULL, 'city', $city);
if(isset($state))
$xslt->setParameter(NULL, 'state', $state);
print $xslt->transformToXML($dom);
?>
<?xml version="1.0"?>
<address-book>
<person id="1">
<!--David Sklar-->
<firstname>David</firstname>
<lastname>Sklar</lastname>
<city>New York</city>
<state>NY</state>
<email>sklar@php.net</email>
</person>
<person id="2">
<!--Adam Trachtenberg-->
<firstname>Adam</firstname>
<lastname>Trachtenberg</lastname>
<city>San Francisco</city>
<state>CA</state>
<email>amt@php.net</email>
</person>
</address-book>
<?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="/address-book/person">
<xsl:choose>
<xsl:when test="(city=$city) and (state=$state)" >
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:when>
<xsl:when test="city=$city" >
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:when>
<xsl:when test="state=$state" >
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

You are in the wrong forum but ...

... it may be to do with how you are using isset() .

Try:

$city = isset($_GET['city']) ? $_GET['city'] : '';
$state = isset($_GET['state']) ? $_GET['state'] : '';
...
$xslt->setParameter(NULL, 'city', $city);//unconditionally
$xslt->setParameter(NULL, 'state', $state);//unconditionally
...

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.