﻿<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:rs='urn:schemas-microsoft-com:rowset'
 	xmlns:z='#RowsetSchema'
	xmlns:date="http://www.ora.com/XSLTCookbook/NS/dates"
    xml:space="default"
	version="1.0">

	<xsl:param name="category"></xsl:param>
	<xsl:param name="title"></xsl:param>
	<xsl:param name="path"></xsl:param>
	<xsl:param name="url"></xsl:param>
	<xsl:param name="height"></xsl:param>
	<xsl:param name="limit" select="100"/>
	<xsl:param name="titleLimit" select="30"/>
	<xsl:strip-space elements="true"/>
	<xsl:output omit-xml-declaration="yes" />
	<xsl:variable name="quot" select="'&quot;'"/>

	<xsl:template match='//rs:data'>
		<div id="wxAddThis">
			<!-- AddThis Button BEGIN -->
			<div class="addthis_toolbox addthis_default_style ">
				<div id="wxAddThis_LabelPrint">Printen:</div>
				<a class="addthis_button_print"></a> 
				<div id="wxAddThis_LabelMail">Doorsturen:</div>
				<a class="addthis_button_email"></a>
				<div id="wxAddThis_LabelShare">Delen:</div>
				<a class="addthis_button_facebook"></a>
				<a class="addthis_button_linkedin"></a>
				<a class="addthis_button_twitter"></a>
				<a class="addthis_button_compact"></a>
			</div>
			<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=ra-4f33b81169d339a6"></script>
			<!-- AddThis Button END -->		</div>
		<table id="wxSiteMapTotal" cellpadding="0" cellspacing="0" border="0"><tr>
			<xsl:apply-templates select='z:row'>
				<xsl:sort select="@ows_Deelgebied" order="ascending" />
			</xsl:apply-templates>
			<xsl:variable name="rows" select="z:row" />
			<xsl:if test="count($rows) &lt; 1">
				Geen items beschikbaar...
			</xsl:if>
		<xsl:text disable-output-escaping="yes">&lt;/td&gt;</xsl:text></tr></table>
	</xsl:template>

	<xsl:template match='z:row'>
    <xsl:variable name="linkUrl">
      <xsl:call-template name="all-before-last-comma">
        <xsl:with-param name="str" select="@ows_URL"/>
      </xsl:call-template>
    </xsl:variable>
	<xsl:variable name="linkName">
      <xsl:call-template name="all-after-last-comma">
        <xsl:with-param name="str1" select="@ows_URL"/>
        <xsl:with-param name="str2" select="$linkUrl"/>
      </xsl:call-template>
	</xsl:variable>
	<xsl:variable name="siteName">
	<xsl:choose>
		<xsl:when test="position() = 1">
			<xsl:value-of select="@ows_Deelgebied" />
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
		 		<xsl:when test="@ows_Deelgebied != preceding-sibling::z:row[1]/@ows_Deelgebied"> 
					<xsl:value-of select="@ows_Deelgebied" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:text></xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
	</xsl:variable>
	
	<xsl:choose>
		<xsl:when test="position() = 1">
			<xsl:text disable-output-escaping="yes">&lt;td id=wxSiteMapColumn0 &gt;</xsl:text>
		</xsl:when>
	</xsl:choose>

	<xsl:choose>
		<xsl:when test="string-length($siteName) != 0">
			<xsl:text disable-output-escaping="yes"> &lt;/td&gt; &lt;td class=wxSiteMapColumn id=wxSiteMapColumn</xsl:text>
			<xsl:value-of select="substring-before($siteName, '.')" disable-output-escaping='yes' />
			<xsl:text disable-output-escaping="yes"> &gt;</xsl:text>
			<div class="wxSiteMapHeader"><xsl:value-of select="substring-after($siteName, '.')" disable-output-escaping='yes' /></div>
		</xsl:when>
	</xsl:choose>
	<xsl:choose>
		<xsl:when test="@ows_Icon != ''">
    		<a><xsl:attribute name="href"><xsl:value-of select='$linkUrl' disable-output-escaping='yes' /></xsl:attribute><img><xsl:attribute name="src"><xsl:value-of select="substring-before(@ows_Icon, ',')" disable-output-escaping='yes' /></xsl:attribute><xsl:attribute name="title">BZW op<xsl:value-of select='$linkName' disable-output-escaping='yes'  /></xsl:attribute></img></a>
		</xsl:when>
		<xsl:otherwise>
			<a><xsl:attribute name="href"><xsl:value-of select='$linkUrl' disable-output-escaping='yes' /></xsl:attribute><xsl:value-of select='$linkName' disable-output-escaping='yes' /></a><br/>
		</xsl:otherwise>
	</xsl:choose>
	</xsl:template>

  <xsl:template name="all-before-last-comma">
    <xsl:param name="str"/>
    <xsl:if test="contains($str, ',')">
      <xsl:value-of select="substring-before($str, ',')"/>
      <xsl:if test="contains(substring-after($str, ','), ',')">
        <xsl:text>,</xsl:text>
      </xsl:if>
      <xsl:call-template name="all-before-last-comma">
        <xsl:with-param name="str" select="substring-after($str, ',')"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>  
  
    <xsl:template name="all-after-last-comma">
    <xsl:param name="str1"/>
    <xsl:param name="str2"/>
    <xsl:choose>
    	<xsl:when test="contains($str1, $str2)">
    		<xsl:value-of select="substring($str1, string-length($str2)+3)"/>
    	</xsl:when>
    	<xsl:otherwise>
    		<xsl:value-of select="$str1"/> - 
    		<xsl:value-of select="$str2"/>
    	</xsl:otherwise>
    </xsl:choose>
  </xsl:template>  

</xsl:stylesheet>
