clearing/clearing-parent/backend-api/src/main/resources/meta/xsl/db.xsl

215 lines
8.4 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes="xalan">
<xsl:output version="1.0" method="html" indent="no" encoding="UTF-8"/>
<xsl:variable name="data" select="document('..\dictionaries.xml')/meta"/>
<xsl:variable name="meta" select="document('..\meta.xml')/meta"/>
<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="avoidletters">_0123456789</xsl:variable>
<xsl:template match="/">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Web</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<style type="text/css">
table.sample {
border-width: 1px 1px 1px 1px;
border-spacing: 2px;
border-style: outset outset outset outset;
border-color: gray gray gray gray;
border-collapse: collapse;
background-color: white;
}
table.sample th {
border-width: 1px 1px 1px 1px;
padding: 1px 1px 1px 1px;
border-style: inset inset inset inset;
border-color: gray gray gray gray;
background-color: white;
-moz-border-radius: 0px 0px 0px 0px;
}
table.sample td {
border-width: 1px 1px 1px 1px;
padding: 1px 1px 1px 1px;
border-style: inset inset inset inset;
border-color: gray gray gray gray;
background-color: white;
}
</style>
</head>
Version: <xsl:value-of select="@version"/>
<xsl:apply-templates select="reports"/>
<xsl:apply-templates select="*"/></xsl:template>
<xsl:template match="meta">-- DB version: <xsl:value-of select="@version"/><xsl:apply-templates select="*"/></xsl:template>
<xsl:template match="enums">
/* Dictionaries */
<xsl:apply-templates select="*" mode="enums"/>
</xsl:template>
<xsl:template match="objects">
/* Business objects */
<xsl:apply-templates select="*" mode="objects"/>
</xsl:template>
<xsl:template match="views">
/* views */
</xsl:template>
<xsl:template match="types">
-- Data types
<xsl:apply-templates select="*" mode="types"/>
</xsl:template>
<xsl:template match="type" mode="types">
-- <xsl:value-of select="@id"/>. <xsl:value-of select="name()"/> : <xsl:value-of select="@type"/> - <xsl:value-of select="@name"/>
<xsl:if test="position() != last()">,</xsl:if>
</xsl:template>
<xsl:template match="*" mode="enums">
<xsl:variable name="dbTableName"><xsl:call-template name='convertDbStyle'><xsl:with-param name='toconvert' select='concat(name(),"Dictionary")'/></xsl:call-template></xsl:variable>
<xsl:variable name="enumName"><xsl:value-of select="name()"/></xsl:variable>
<h3><xsl:value-of select="position()"/>. <xsl:value-of select="@name"/> - <xsl:value-of select="$dbTableName"/>( <xsl:value-of select="name()"/>)</h3>
<table class="sample" width="100%" border="0">
<tr><td width="10%">№</td><td width="20%">Поле</td><td width="20%">Тип</td><td width="45%">Наименование</td></tr>
<xsl:apply-templates select="*" mode="comment-enums"/>
</table>
<a name="enums.{name()}"/>
<div>Значения:</div>
<xsl:for-each select="xalan:nodeset($data)/enums/*[name()=$enumName]">
<xsl:value-of select="@id"/>. <xsl:value-of select="@code"/> - <i><xsl:value-of select="@name"/></i><br/>
</xsl:for-each>
</xsl:template>
<xsl:template match="*" mode="objects">
<xsl:variable name="dbTableName"><xsl:call-template name='convertDbStyle'><xsl:with-param name='toconvert' select='name()'/></xsl:call-template></xsl:variable>
<h3><xsl:value-of select="position()"/>. <xsl:value-of select="@name"/> - <xsl:value-of select="$dbTableName"/>( <xsl:value-of select="name()"/>)</h3>
<table class="sample" width="100%" border="0">
<tr><td width="10%">№</td><td width="20%">Поле</td><td width="20%">Тип</td><td width="45%">Наименование</td></tr>
<xsl:apply-templates select="*" mode="comment-objects"/>
</table>
</xsl:template>
<xsl:template match="*" mode="field" >
<xsl:if test="position() != '1'">, </xsl:if>
<xsl:variable name="tp" select="@type"/>
<xsl:choose>
<xsl:when test="@dbfield"><xsl:value-of select="@dbfield"/></xsl:when>
<xsl:otherwise><xsl:call-template name='convertDbStyle'><xsl:with-param name='toconvert' select='name()'/></xsl:call-template></xsl:otherwise>
</xsl:choose>&#160;<xsl:value-of select="/meta/types/*[@id=$tp]/@type"/>
<xsl:if test="@length">(<xsl:value-of select="@length"/>)</xsl:if><xsl:if test="name()='id'"> PRIMARY KEY</xsl:if>
</xsl:template>
<xsl:template match="*" mode="comment-enums">
<tr>
<td width="5%"><xsl:value-of select="position()"/></td>
<td width="10%"><xsl:call-template name='convertDbStyle'><xsl:with-param name='toconvert' select='name()'/></xsl:call-template></td>
<td width="20%"><xsl:variable name="fieldType"><xsl:value-of select="@type"/></xsl:variable>
<xsl:value-of select="$meta/types/*[@id=$fieldType]/@type"/>
<xsl:if test="@length">(<xsl:value-of select="@length"/>)</xsl:if>
</td>
<td width="45%"><xsl:if test="@name"><xsl:value-of select="@name"/></xsl:if> <xsl:if test="@link"> (linked to <xsl:value-of select="@link"/>)</xsl:if></td></tr>
</xsl:template>
<xsl:template match="*" mode="comment-objects">
<xsl:if test="name() != 'actions'">
<tr>
<td width="5%"><xsl:value-of select="position()"/></td>
<td width="10%"><xsl:call-template name='convertDbStyle'><xsl:with-param name='toconvert' select='name()'/></xsl:call-template></td>
<td width="20%"><xsl:variable name="fieldType"><xsl:value-of select="@type"/></xsl:variable>
<xsl:value-of select="$meta/types/*[@id=$fieldType]/@type"/>
<xsl:if test="@length">(<xsl:value-of select="@length"/>)</xsl:if>
</td>
<td width="45%"><xsl:if test="@name"><xsl:value-of select="@name"/></xsl:if> <xsl:if test="@link"> (linked to <xsl:value-of select="@link"/>)</xsl:if></td></tr>
</xsl:if>
</xsl:template>
<xsl:template name='convertDbStyle'>
<xsl:param name='toconvert' />
<xsl:variable name="added_">
<xsl:call-template name='add_'>
<xsl:with-param name='toconvert' select='$toconvert' />
</xsl:call-template>
</xsl:variable>
<xsl:call-template name='convertcase'>
<xsl:with-param name='toconvert' select='$added_' />
<xsl:with-param name='conversion' select="'upper'" />
</xsl:call-template>
</xsl:template>
<xsl:template name='convertcase'>
<xsl:param name='toconvert' />
<xsl:param name='conversion' />
<xsl:choose>
<xsl:when test='$conversion="lower"'>
<xsl:value-of select="translate($toconvert,$ucletters,$lcletters)"/>
</xsl:when>
<xsl:when test='$conversion="upper"'>
<xsl:value-of select="translate($toconvert,$lcletters,$ucletters)"/>
</xsl:when>
<xsl:when test='$conversion="proper"'>
<xsl:call-template name='convertpropercase'>
<xsl:with-param name='toconvert'>
<xsl:value-of select="translate($toconvert,$ucletters,$lcletters)"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$toconvert' />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name='convertpropercase'>
<xsl:param name='toconvert' />
<xsl:if test="string-length($toconvert) > 0">
<xsl:variable name='f' select='substring($toconvert, 1, 1)' />
<xsl:variable name='s' select='substring($toconvert, 2)' />
<xsl:call-template name='convertcase'>
<xsl:with-param name='toconvert' select='$f' />
<xsl:with-param name='conversion'>upper</xsl:with-param>
</xsl:call-template>
<xsl:choose>
<xsl:when test="contains($s,' ')">
<xsl:value-of select='substring-before($s," ")'/>
<xsl:call-template name='convertpropercase'>
<xsl:with-param name='toconvert' select='substring-after($s," ")' />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select='$s'/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template name='add_'>
<xsl:param name='toconvert' />
<xsl:if test="string-length($toconvert) > 0">
<xsl:variable name='f' select='substring($toconvert, 1, 1)' />
<xsl:variable name='s' select='substring($toconvert, 2)' />
<xsl:choose>
<xsl:when test="$f = translate($f, $lcletters,$ucletters)"><xsl:if test="translate($f, $avoidletters,'')">_</xsl:if><xsl:value-of select='$f'/></xsl:when>
<xsl:otherwise><xsl:value-of select='$f'/></xsl:otherwise>
</xsl:choose>
<xsl:if test="string-length($toconvert) > 1">
<xsl:call-template name='add_'>
<xsl:with-param name='toconvert' select='$s'/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>