I use xml and xslt to generate the desired html. In my previous post, I was able to generate all the records, however, I was a little confused how to get the filter data according to the xslt parameter values.
I have two controls on my first page for selection, and the second one to display entries according to the values passed from the selection control.
The following are xmls and xslt, which are used to create a second usercontrol (display all entries).
1) Destinations.xml
<?xml version="1.0"?> <list type="Destinations"> <resources location="include/xml/locations.xml"> <publication>481</publication> </resources> <destination id="594051" title="Sydney" url="/asiapacific/australia/sydney.aspx" > <city id="192409" /> </destination> <destination id="594088" title="Brisbane" url="/asiapacific/australia/brisbane.aspx" > <city id="192397" /> </destination> <destination id="594579" title="Dubai" url="/middleeast/uae/dubai.aspx" > <city id="192855" /> </destination> <destination id="594580" title="Abu Dhabi" url="/middleeast/uae/abudhabi.aspx" > <city id="192851" /> </destination> </list>
2) Locations.xml
<?xml version="1.0"?> <list type="Locations"> <region id="192393" code="ASIA" name="Asia & the Pacific" shortname="Asia & the Pacific"> <country id="192395" code="AU" name="Australia" shortname="Australia"> <city id="192397" code="BNE" name="Brisbane" shortname="Brisbane"> <airport id="192399" code="BNE" name="Brisbane International Airport" shortname="Brisbane"></airport> </city> <city id="192409" code="SYD" name="Sydney" shortname="Sydney"> <airport id="192411" code="SYD" name="Kingsford Smith Airport" shortname="Sydney"></airport> </city> </country> </region> <region id="192847" code="MEAF" name="The Middle East & Africa" shortname="The Middle East & Africa"> <country id="192849" code="AE" name="United Arab Emirates" shortname="United Arab Emirates"> <city id="192851" code="AUH" name="Abu Dhabi" shortname="Abu Dhabi"> <airport id="192853" code="AUH" name="Abu Dhabi" shortname="Abu Dhabi"></airport> </city> <city id="192855" code="DXB" name="Dubai" shortname="Dubai"> <airport id="192857" code="DXB" name="Dubai International Airport" shortname="Dubai"></airport> </city> </country> </region> </list>
1) Veiwalldestinations.xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:tlink="urn:TridionLinking" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:utils="urn:XSLTExtensions" exclude-result-prefixes="xsl xlink tlink msxsl utils"> <xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="yes" /> <xsl:include href="dynamic_linking.xslt"/> <xsl:key name="kCityById" match="city" use="@id"/> <xsl:variable name="vLocations" select="document(concat($publicationPath, /list/resources/@location))/list"/> <xsl:variable name="destination" select="/list"/> <xsl:param name="publicationPath"/> <xsl:param name="pubURL"/> <xsl:param name="pageURL"/> <xsl:param name="region"/> <xsl:param name="country"/> <xsl:template match="/list"> <div class="brownBarContainer"> <div class="brownBar"> All Destinations </div> </div> <table width="100%" cellspacing="0" cellpadding="0" border="0" class="displayTable"> <tbody> <tr> <th scope="col" class="first sortSelected"> <div class="thPadding"> <a class="iconDownSortArrow" href="#">Destination</a> </div> </th> <th scope="col" class="sortHover"> <div class="thPadding"> <a class="iconSortArrowOff" href="#">Country</a> </div> </th> <th scope="col" class="sortHover"> <div class="thPadding"> <a class="iconSortArrowOff" href="#">Region</a> </div> </th> </tr> <xsl:apply-templates select="destination"></xsl:apply-templates> </tbody> </table> </xsl:template> <xsl:template match="text()"/> <xsl:template match="destination"> <xsl:variable name="vReverseURL"> <xsl:call-template name="reverse"> <xsl:with-param name="string" select="@url"/> </xsl:call-template> </xsl:variable> <xsl:variable name="vCountryURL"> <xsl:call-template name="reverse"> <xsl:with-param name="string" select="substring-after($vReverseURL,'/')"/> </xsl:call-template> <xsl:text>/index.aspx</xsl:text> </xsl:variable> <xsl:variable name="vRegionURL"> <xsl:call-template name="reverse"> <xsl:with-param name="string" select="substring-after(substring-after($vReverseURL,'/'),'/')"/> </xsl:call-template> <xsl:text>/index.aspx</xsl:text> </xsl:variable> <xsl:variable name="current" select="."/> <xsl:for-each select="$vLocations"> <tr> <td class="detail first"> <a class="arrowSmallFront" href="{$current/@url}"> <xsl:value-of select="$current/@title"/> </a> </td> <td class="detail noLeftBorder"> <a class="arrowSmallFront" href="{$vCountryURL}"> <xsl:value-of select="key('kCityById',$current/city/@id)/../@name"/> </a> </td> <td class="detail noLeftBorder"> <a class="arrowSmallFront" href="{$vRegionURL}"> <xsl:value-of select="key('kCityById',$current/city/@id)/../../@name"/> </a> </td> </tr> </xsl:for-each> </xsl:template> <xsl:template name="reverse"> <xsl:param name="string" select="''"/> <xsl:if test="$string != ''"> <xsl:call-template name="reverse"> <xsl:with-param name="string" select="substring($string,2)"/> </xsl:call-template> <xsl:value-of select="substring($string,1,1)"/> </xsl:if> </xsl:template> </xsl:stylesheet>
If you see two parameters in xslt, these are IDs coming from the top user control (selection)
<xsl:param name="region"/> <xsl:param name="country"/>
Now I want to show records in accordance with the regions and country identifiers, I can get all records when there are no registers and country identifiers. For example, if the Asia and the World region with ID = 192393 is selected in the usercontrol, then only all destinations associated with this region will appear, and if the user selects the desired country in the region, then he will only show entries related only to this country. For example, if the user selects the region "Asia and the world", and the country "Australia", then xslt will show only "Sydney" and "Brisbane" in accordance with the above xmls.
The relationship between destination.xml and locations.xmls is associated with city identifiers
Secondary, I want to sort the destination, when the user clicks on the destination header, please look above xslt below htmls
<th scope="col" class="first sortSelected"> <div class="thPadding"> <a class="iconDownSortArrow" href="#">Destination</a> </div> </th>
Thank you and sorry for the long questions. Please suggest!