<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:iteraplan="urn:iteraplan">
  <xsl:output method="html" indent="yes" encoding="UTF-8" omit-xml-declaration="yes"/>
  
  <xsl:variable name="fullModel" select="/iteraplan:Container" />
  
  <xsl:template match="iteraplan:Container">
    [INFO] Content was written to crudMatrix.html which can be loaded from the file list on the right!
  	<xsl:result-document href="crudMatrix.html">
  	<html>
  	  <head><style>
		table {border-collapse: collapse; border-spacing: 1px; border-color: grey;}
		table td {text-align: center; padding: 10px 5px; border: 1px solid #ccc;}
		th {height: 200px; white-space: nowrap;}
		th > div {transform: translate(17px, 81px) rotate(315deg); width: 30px;}
		th > div > span {border-bottom: 1px solid #ccc; padding: 5px 10px;}
	  </style></head>
	  
	  <body>
	    <table>
	      <!-- header row, containing names of the information systems -->
  	  	  <tr>
  	  	  	<th></th>
  	    	<xsl:for-each select="contents[@xsi:type='iteraplan:InformationSystem']">
  	    	  <th><div><span><xsl:value-of select="./@name" /></span></div></th>
  	    	</xsl:for-each>
  	  	  </tr>
	  	  
	  	  <!-- content rows -->
	  	  <xsl:apply-templates select="contents[@xsi:type='iteraplan:BusinessObject']" />
	  	  
		</table>
	  </body>
	</html>
	</xsl:result-document>
  </xsl:template>
  
  
  
  <xsl:template match="iteraplan:Container/contents[@xsi:type='iteraplan:BusinessObject']">
    <xsl:variable name="BOID" select="concat('#', ./@id)" />
    
    <tr>
      <!-- header column, containing names of the business objects -->
      <td><xsl:value-of select="./@name" /></td>
      
      <!-- content columns -->
      <xsl:for-each select="$fullModel/contents[@xsi:type='iteraplan:InformationSystem']">
        <xsl:variable name="ISID" select="concat('#', ./@id)" />
        <xsl:variable name="ISBO" select="$fullModel/contents[@informationSystem=$ISID and @businessObject=$BOID]" />
        
        <xsl:variable name="CRUD">
          <xsl:choose>
            <xsl:when test="$ISBO/text()"><xsl:value-of select="$ISBO/CRUD" /></xsl:when>
            <xsl:when test="$ISBO/@id > 0">X</xsl:when>
          </xsl:choose>
        </xsl:variable>
        
        <td><xsl:value-of select="$CRUD" /></td>
      </xsl:for-each>
    </tr>
    
  </xsl:template>

</xsl:stylesheet>