<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:js="http://mycompany.com/mynamespace">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes" encoding="ISO-8859-1" media-type="image/svg"/>

<xsl:template match="gruppi">
	<svg width="1100" height="2500" zoomAndPan="magnify"
		xmlns:adobe="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" adobe:scriptImplementation="Adobe">
		<script type="text/ecmascript" xlink:href="../metamorfosi/SvgScrollBars.js" adobe:scriptImplementation="Adobe"/>
		
		<defs>
		    <filter id="MyFilter" filterUnits="userSpaceOnUse" x="-10" y="0" width="600" height="20">
		      <feGaussianBlur in="SourceAlpha" stdDeviation="2" result="blur"/>
		      <feOffset in="blur" dx="2" dy="2" result="offsetBlur"/>
		      <feSpecularLighting in="blur" surfaceScale="5" specularConstant=".75" 
		                          specularExponent="20" lighting-color="#ffffff"  
		                          result="specOut">
		        <fePointLight x="-5000" y="-10000" z="20000"/>
		      </feSpecularLighting>
		      <feComposite in="specOut" in2="SourceAlpha" operator="in" result="specOut"/>
		      <feComposite in="SourceGraphic" in2="specOut" operator="arithmetic" 
		                   k1="0" k2="1" k3="1" k4="0" result="litPaint"/>
		      <feMerge>
		        <feMergeNode in="offsetBlur"/>
		        <feMergeNode in="litPaint"/>
		      </feMerge>
		    </filter>
			<g id="Link">
				<polyline fill="none" stroke="#990000" stroke-width="2" points="0,4 4,8 0,12"/>
				<polyline fill="none" stroke="#990000" stroke-width="2" points="4,4 8,8 4,12"/>
			</g>
			<g id="Linea">
				<line filter="url(#MyFilter)" x1="0" x2="576" y1="5" y2="5" stroke="#990000" stroke-width="4"/>
				<line filter="url(#MyFilter)" x1="580" x2="584" y1="5" y2="5" stroke="#990000" stroke-width="4"/>
			</g> 
			<g id="Quadrato">
				<rect filter="url(#MyFilter)" fill="#990000" x="0" y="5" height="7" width="7"/>
			</g>
			<g id="EMail">
				<rect stroke="#990000" fill="none" stroke-width="2" x="0" y="5" height="8" width="16"/>
				<polyline fill="none" stroke="#990000" stroke-width="2" points="0,5 8,10 16,5"/>
				<line x1="1" y1="13" x2="5" y2="8" stroke="#990000" stroke-width="1"/>
				<line x1="15" y1="13" x2="11" y2="8" stroke="#990000" stroke-width="1"/>
			</g>
		</defs>
		<g transform="translate(20, 0)">
		<xsl:call-template name="Logo"/>
		<text x="35" y="30" style="font-weight: bold;"><xsl:value-of select="@h1"/>&#xA0;<tspan style="font-weight: normal;"><xsl:value-of select="@tipo"/></tspan></text>
		<xsl:apply-templates select="gruppo"/>

		<xsl:variable name="y0" select="js:leggiPos(15)"/>
		<use x="0" y="{$y0}" xlink:href="#Linea"/>
		</g>
	</svg> 
</xsl:template> 

<xsl:template match="gruppo">
	<xsl:variable name="y0" select="js:leggiPos(10)"/>
	<use x="0" y="{$y0}" xlink:href="#Linea"/>

	<xsl:variable name="y" select="js:leggiPos(35)"/>
	
	<text x="0" y="{$y}" style="font-weight: bold;"><xsl:value-of select="@h2"/>&#xA0;<tspan style="font-weight: normal;"><xsl:value-of select="@tipo"/></tspan></text>
	<xsl:value-of select="js:leggiPos(5)"/>	

	<xsl:apply-templates select="p"/>
	<xsl:apply-templates select="cliente"/>
	<xsl:apply-templates select="email"/>
</xsl:template>

<xsl:template match="p">
 	<xsl:variable name="y" select="js:leggiPos(5)"/>
	<xsl:value-of select="js:storeBuffer(.)"/>
	<text y="{$y}" style="font-size: 12; font-family: Verdana; fill: black;">
		<xsl:call-template name="tagliaTesto"/>
	</text>
	<xsl:value-of select="js:leggiPos(5)"/>
</xsl:template>

<xsl:template name="tagliaTesto">
	<tspan x="0" dy="15"><xsl:value-of select="js:taglia(95)"/></tspan>
	<xsl:if test="js:leggiBuffer()!=''">
		<xsl:call-template name="tagliaTesto"/>
	</xsl:if>
</xsl:template>

<xsl:template match="cliente">
	<xsl:variable name="y" select="js:leggiPos(5)"/>	
	
	<use x="0" y="{$y}" xlink:href="#Quadrato"/>

	<xsl:value-of select="js:storeBuffer(descrizione/child::node())"/>
	<text y="{$y}" style="font-size: 12; font-family: Verdana; fill: black;">
		<tspan x="15" dy="15"><xsl:value-of select="js:taglia(95)"/></tspan>
		<xsl:if test="js:leggiBuffer()!=''">
			<xsl:call-template name="tagliaTesto"/>
		</xsl:if>
	</text>
	<xsl:apply-templates select="link"/>
	<xsl:value-of select="js:leggiPos(5)"/>	
</xsl:template>

<xsl:template match="link">
	<xsl:variable name="y0" select="js:leggiPos(6)"/>
	<xsl:variable name="y" select="js:leggiPos(12)"/>
	<use x="0" y="{$y0}" xlink:href="#Link"/>
	<a>
		<xsl:attribute name="xlink:href">
			<xsl:value-of select="@href"/>
		</xsl:attribute>
		<text x="15" y="{$y}" style="font-size: 12; font-family: Verdana; fill: black; text-decoration: underline">
			<xsl:if test=".=''"><xsl:value-of select="@href"/></xsl:if>
			<xsl:if test="not(.='')"><xsl:apply-templates/></xsl:if>
		</text>
	</a>
</xsl:template>

<xsl:template match="email">
	<xsl:variable name="y0" select="js:leggiPos(6)"/>
	<xsl:variable name="y" select="js:leggiPos(12)"/>
	<use x="0" y="{$y0}" xlink:href="#EMail"/>
	<a><xsl:attribute name="xlink:href">mailto:<xsl:value-of select="@href"/></xsl:attribute>
		<text x="25" y="{$y}" style="font-size: 12; font-family: Verdana; fill: black; text-decoration: underline">
			<xsl:value-of select="@href"/>
		</text>
	</a>
</xsl:template>

<xsl:template name="Logo">	 
    <filter id="MyFilter2" filterUnits="userSpaceOnUse" x="0" y="0" width="30" height="40">
      <feGaussianBlur in="SourceAlpha" stdDeviation="2.5" result="blur"/>
      <feOffset in="blur" dx="1" dy="1" result="offsetBlur"/>
      <feSpecularLighting in="blur" surfaceScale="5" specularConstant=".75" 
                          specularExponent="20" lighting-color="#ffffff"  
                          result="specOut">
        <fePointLight x="-5000" y="-10000" z="20000"/>
      </feSpecularLighting>
      <feComposite in="specOut" in2="SourceAlpha" operator="in" result="specOut"/>
      <feComposite in="SourceGraphic" in2="specOut" operator="arithmetic" 
                   k1="0.25" k2="0.9" k3="0.15" k4="0" result="litPaint"/>
      <feMerge>
        <feMergeNode in="offsetBlur"/>
        <feMergeNode in="litPaint"/>
      </feMerge>
    </filter>

	<rect filter="url(#MyFilter2)" fill="#990000" x="0" y="15" height="20" width="20"/>
  
  <g id="Logo" transform="translate(10.7,15) scale(0.00224)">
  <g>
  	<path style="fill:#852A2C" d="M-4792 8925l335 -336 0 -8254 -335 -335 0 8925z"/>
	<path style="fill:#852A2C" d="M4133 0l-335 335 0 8254 335 336 0 -8925z"/>
	<path style="fill:#A82C32" d="M-4792 0l335 335 8255 0 335 -335 -8925 0z"/>
	<path style="fill:#B22C32" d="M-4457 335l8255 0 0 8254 -8255 0 0 -8254z"/>
  </g>
  <path style="fill:#151619" d="M-1326 5563c-1261,-126 -2231,-1203 -2231,-2473 0,-1368 1115,-2483 2483,-2483 970,0 1872,582 2270,1464l-2522 3492z"/>
  <g>
   <path style="fill:#C94D46" d="M1023 1755l-202 132 81 137 12 23 282 24 -81 -162 -92 -154z"/>
   <path style="fill:#BA3D36" d="M275 1008l-130 204 130 91 126 100 117 109 109 117 101 124 93 134 202 -132 -102 -146 -112 -139 -121 -129 -130 -121 -138 -111 -145 -101z"/>
   <path style="fill:#A32C2A" d="M-714 634l-35 239 157 29 156 41 152 52 148 62 142 72 139 83 130 -204 -152 -90 -158 -80 -163 -69 -168 -57 -173 -46 -175 -32z"/>
   <path style="fill:#942B2A" d="M-1811 719l72 231 215 -56 221 -34 230 -11 162 6 162 18 35 -239 -179 -20 -181 -7 -253 13 -246 37 -238 62z"/>
   <path style="fill:#942B2A" d="M-2828 1335l171 171 159 -144 173 -130 184 -112 196 -94 206 -76 -72 -231 -228 84 -217 104 -205 125 -191 143 -176 160z"/>
   <path style="fill:#942B2A" d="M-3445 2353l231 72 76 -206 94 -196 113 -184 129 -173 145 -160 -171 -171 -161 177 -143 191 -125 205 -104 217 -84 228z"/>
   <path style="fill:#942B2A" d="M-3546 3325l241 -23 -10 -213 12 -228 34 -222 55 -214 -231 -72 -61 237 -38 247 -13 253 11 235z"/>
   <path style="fill:#A12C2A" d="M-3184 4397l206 -128 -99 -177 -83 -186 -67 -195 -48 -201 -30 -208 -241 23 33 230 54 224 73 215 92 207 110 196z"/>
   <path style="fill:#B83B35" d="M-2403 5189l131 -204 -166 -117 -155 -131 -141 -144 -129 -156 -115 -168 -206 128 127 185 143 173 157 160 171 145 183 129z"/>
   <path style="fill:#D05750" d="M-1326 5563l-111 -261 -75 -12 -203 -50 -194 -68 -187 -86 -176 -101 -131 204 196 113 207 94 216 76 225 56 233 35z"/>
   <path style="fill:none" d="M-1326 5563l-111 -261 -75 -12 -203 -50 -194 -68 -187 -86 -176 -101 -166 -117 -155 -131 -141 -144 -129 -156 -115 -168 -99 -177 -83 -186 -67 -195 -48 -201 -30 -208 -10 -213 12 -228 34 -222 55 -214 76 -206 94 -196 113 -184 129 -173 145 -160 159 -144 173 -130 184 -112 196 -94 206 -76 215 -56 221 -34 230 -11 162 6 162 18 157 29 156 41 152 52 148 62 142 72 139 83 130 91 126 100 117 109 109 117 101 124 93 134 81 137 12 23 282 24 -81 -162 -92 -154 -102 -146 -112 -139 -121 -129 -130 -121 -138 -111 -145 -101 -152 -90 -158 -80 -163 -69 -168 -57 -173 -46 -175 -32 -179 -20 -181 -7 -253 13 -246 37 -238 62 -228 84 -217 104 -205 125 -191 143 -176 160 -161 177 -143 191 -125 205 -104 217 -84 228 -61 237 -38 247 -13 253 11 235 33 230 54 224 73 215 92 207 110 196 127 185 143 173 157 160 171 145 183 129 196 113 207 94 216 76 225 56 233 35z"/>
   <path style="fill:#DC7D76" d="M1196 2071l-282 -24 -2351 3255 111 261 2522 -3492z"/>
   <path style="fill:none" d="M1196 2071l-282 -24 -2351 3255 111 261 2522 -3492z"/>
   <path style="fill:#FFFFFF" d="M-1437 5302l-75 -12 -203 -50 -194 -68 -187 -86 -176 -101 -166 -117 -155 -131 -141 -144 -129 -156 -115 -168 -99 -177 -83 -186 -67 -195 -48 -201 -30 -208 -10 -213 12 -228 34 -222 55 -214 76 -206 94 -196 113 -184 129 -173 145 -160 159 -144 173 -130 184 -112 196 -94 206 -76 215 -56 221 -34 230 -11 162 6 162 18 157 29 156 41 152 52 148 62 142 72 139 83 130 91 126 100 117 109 109 117 101 124 93 134 81 137 12 23 -2351 3255z"/>
  </g>
  <path style="fill:#151619" d="M667 3361c1261,126 2231,1203 2231,2473 0,1368 -1116,2483 -2483,2483 -970,0 -1872,-582 -2270,-1464l2522 -3492z"/>
  <g>
   <path style="fill:#DC7971" d="M-1683 7169l203 -132 -81 -137 -12 -23 -282 -24 81 162 91 154z"/>
   <path style="fill:#DC7D76" d="M-935 7916l131 -204 -131 -91 -125 -100 -117 -109 -109 -117 -101 -124 -93 -134 -203 132 102 146 112 139 122 129 129 121 138 111 145 101z"/>
   <path style="fill:#DC7971" d="M55 8290l35 -239 -157 -29 -157 -41 -152 -52 -147 -62 -143 -72 -138 -83 -131 204 152 90 158 80 164 69 168 57 172 46 176 32z"/>
   <path style="fill:#D9685E" d="M1152 8205l-72 -231 -215 56 -222 34 -229 11 -162 -6 -162 -18 -35 239 179 20 181 7 253 -13 246 -37 238 -62z"/>
   <path style="fill:#C34640" d="M2169 7589l-171 -171 -159 144 -174 130 -184 112 -195 94 -206 76 72 231 228 -84 217 -104 204 -125 192 -143 176 -160z"/>
   <path style="fill:#AB2E2C" d="M2786 6571l-231 -72 -76 206 -95 196 -112 184 -129 173 -145 160 171 171 161 -177 143 -191 124 -205 105 -217 84 -228z"/>
   <path style="fill:#972829" d="M2886 5599l-241 23 10 213 -11 228 -34 222 -55 214 231 72 61 -237 38 -247 13 -253 -12 -235z"/>
   <path style="fill:#942B2A" d="M2524 4527l-205 128 99 177 83 186 66 195 49 201 29 208 241 -23 -32 -230 -54 -224 -74 -215 -92 -207 -110 -196z"/>
   <path style="fill:#942B2A" d="M1743 3735l-131 204 167 117 154 131 142 144 129 156 115 168 205 -128 -126 -185 -143 -173 -157 -160 -171 -145 -184 -129z"/>
   <path style="fill:#942B2A" d="M667 3361l110 261 76 12 203 50 194 68 187 86 175 101 131 -204 -195 -113 -207 -94 -216 -76 -225 -56 -233 -35z"/>
   <path style="fill:none" d="M667 3361l110 261 76 12 203 50 194 68 187 86 175 101 167 117 154 131 142 144 129 156 115 168 99 177 83 186 66 195 49 201 29 208 10 213 -11 228 -34 222 -55 214 -76 206 -95 196 -112 184 -129 173 -145 160 -159 144 -174 130 -184 112 -195 94 -206 76 -215 56 -222 34 -229 11 -162 -6 -162 -18 -157 -29 -157 -41 -152 -52 -147 -62 -143 -72 -138 -83 -131 -91 -125 -100 -117 -109 -109 -117 -101 -124 -93 -134 -81 -137 -12 -23 -282 -24 81 162 91 154 102 146 112 139 122 129 129 121 138 111 145 101 152 90 158 80 164 69 168 57 172 46 176 32 179 20 181 7 253 -13 246 -37 238 -62 228 -84 217 -104 204 -125 192 -143 176 -160 161 -177 143 -191 124 -205 105 -217 84 -228 61 -237 38 -247 13 -253 -12 -235 -32 -230 -54 -224 -74 -215 -92 -207 -110 -196 -126 -185 -143 -173 -157 -160 -171 -145 -184 -129 -195 -113 -207 -94 -216 -76 -225 -56 -233 -35z"/>
   <path style="fill:#BE433D" d="M-1855 6853l282 24 2350 -3255 -110 -261 -2522 3492z"/>
   <path style="fill:none" d="M-1855 6853l282 24 2350 -3255 -110 -261 -2522 3492z"/>
   <path style="fill:#FFFFFF" d="M777 3622l76 12 203 50 194 68 187 86 175 101 167 117 154 131 142 144 129 156 115 168 99 177 83 186 66 195 49 201 29 208 10 213 -11 228 -34 222 -55 214 -76 206 -95 196 -112 184 -129 173 -145 160 -159 144 -174 130 -184 112 -195 94 -206 76 -215 56 -222 34 -229 11 -162 -6 -162 -18 -157 -29 -157 -41 -152 -52 -147 -62 -143 -72 -138 -83 -131 -91 -125 -100 -117 -109 -109 -117 -101 -124 -93 -134 -81 -137 -12 -23 2350 -3255z"/>
  </g>
  </g>
</xsl:template>

<msxsl:script language="JScript" implements-prefix="js"><![CDATA[
var righe=1;
var buffer="";
var pos=35;

function leggiPos(n) {
	pos += n;
	return pos;
}

function storeBuffer(valore) {
	buffer = valore.nextNode().xml;
	buffer = buffer.replace("<p>","");
	buffer = buffer.replace("</p>","");
	righe=1;
	return "";
}

function leggiBuffer() {
	return buffer;
}

function taglia(n) {
	var b = buffer.substr(0, n);
	var a = b.indexOf("<br/>");
	if (a>0) {
		b = buffer.substr(0, a);
		buffer = buffer.substring(a+5, buffer.length);
	} else {
		if (buffer.length>n) {
			a = b.lastIndexOf(" ");
			b = buffer.substr(0, a);
			buffer = buffer.substring(a+1, buffer.length);
		} else {
			buffer="";
			pos+=righe*15;
		}
	}  
	righe++;
	return b; 
}
]]></msxsl:script>

</xsl:stylesheet> 