i need help in getting the below output from shops.xml file( where incity=”yes” and type=”Botique” ) by using xsl . As i am new to xslt , so any help would be highly appreciated.
shops.xml:
<shops>
<shop incity="yes" onlineorder="yes">
<type>Botique</type>
<address>
<streetno>23</streetno>
<streetname>collins</streetname>
<suburb>Melbourne</suburb>
</address>
</shop>
<shop incity="yes" onlineorder="yes">
<type>Botique</type>
<address>
<streetno>25</streetno>
<streetname>little collins</streetname>
<suburb>Melbourne</suburb>
</address>
</shop>
<shop incity="no" onlineorder="yes">
<type>Tailoring</type>
<address>
<streetno>2</streetno>
<streetname>cosmos street</streetname>
<suburb>Glenroy</suburb>
</address>
</shop>
</shops>
output:
<shops>
<shop onlineorder="yes">
<type>Botique</type>
<address> 23 collins,Melbourne </address>
</shop>
<shop onlineorder="yes">
<type>Botique</type>
<address> 25 little collins, Melbourne </address>
</shop>
</shops>
shop.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="shop[@incity='no']" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
shop.php
<?php
$xmlDoc = new DOMDocument('1.0');
$xmlDoc->formatOutput = true;
$xmlDoc->load("shops.xml");
$xslDoc = new DomDocument;
$xslDoc->load("shop.xsl");
$proc = new XSLTProcessor;
$proc->importStyleSheet($xslDoc);
$strxml= $proc->transformToXML($xmlDoc);
echo ($strxml);
?>
Here’s something to start with:
Output: