KeyPoolHelper.xsl 9.2 KB
Newer Older
1
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="xsl msxsl">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
	<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
	<xsl:template name="ToLower">
		<xsl:param name="input"/>
		<xsl:value-of select="translate($input, $uppercase, $lowercase)"/>
	</xsl:template>
	<xsl:template name="remove">
		<xsl:param name="input"/>
		<xsl:param name="removal"/>
		<xsl:param name="exchangevalue" select="''"/>
		<xsl:choose>
			<xsl:when test="$exchangevalue != ''">
				<xsl:value-of select="translate($input, $removal, $exchangevalue)"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="translate($input, $removal, '')"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="getTargetElementName">
		<xsl:param name="KeyPool"/>
		<xsl:variable name="splitter" select="concat(concat(local-name(), ' '),'Sim')"/>
		<xsl:variable name="headtuple">
			<xsl:value-of select="concat(concat($splitter, substring-before(substring-after($KeyPool, $splitter), '§')),'§')"/>
		</xsl:variable>
		<xsl:variable name="evaltargetname">
			<xsl:value-of select="normalize-space(substring-after(substring-before($headtuple, '§'), ' '))"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="contains($evaltargetname, ' ')">
				<xsl:choose>
					<xsl:when test="contains(substring-after($evaltargetname, ' '), ' ')">
						<xsl:value-of select="normalize-space( substring-after( substring-after($evaltargetname, ' '), ' ') )"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="normalize-space(substring-after($evaltargetname, ' '))"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy-of select="$evaltargetname"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="getTargetElementNames">
		<xsl:param name="KeyPool"/>
		<xsl:variable name="splitter" select="concat(concat(local-name(), ' '),'Sim')"/>
		<xsl:variable name="headtuple">
			<xsl:value-of select="concat(concat($splitter, substring-before(substring-after($KeyPool, $splitter), '§')),'§')"/>
		</xsl:variable>
		<xsl:variable name="evaltargetname">
			<xsl:value-of select="normalize-space(substring-after(substring-before($headtuple, '§'), ' '))"/>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="contains($evaltargetname, ' ')">
				<xsl:choose>
					<xsl:when test="contains(substring-after($evaltargetname, ' '), ' ')">
						<xsl:value-of select="normalize-space( substring-after( substring-after($evaltargetname, ' '), ' ') )"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="normalize-space(substring-after($evaltargetname, ' '))"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy-of select="concat(' ', $evaltargetname)"/>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:if test="contains(substring-after($KeyPool, $splitter), $splitter)">
			<xsl:call-template name="getTargetElementNames">
				<xsl:with-param name="KeyPool" select="substring-after(substring-after($KeyPool, $splitter), ' ')"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	<xsl:template name="KeyPoolHelper">
		<xsl:param name="currentElement"/>
		<xsl:param name="parentElement"/>
		<xsl:variable name="localname">
			<xsl:choose>
				<xsl:when test="contains($currentElement,':')">
					<xsl:value-of select="substring-after($currentElement,':')"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$currentElement"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="currentKeyPool">
			<xsl:variable name="buildKeyPool">
				<xsl:call-template name="KeyPoolBuilder">
					<xsl:with-param name="ElementName" select="$localname"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:choose>
				<xsl:when test="current()/*[@xsi:type ='IfcDistributionSystem' and @GlobalId or @xsi:type = 'ifc:IfcDistributionSystem']">
					<xsl:variable name="realname" select="local-name()"/>
					<xsl:value-of select="$buildKeyPool"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:copy-of select="msxsl:node-set($buildKeyPool)"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="keypoolnodes">
			<xsl:call-template name="postevalkeypool">
				<xsl:with-param name="KeyPoolSnippet" select="$currentKeyPool"/>
				<xsl:with-param name="localname" select="$localname"/>
			</xsl:call-template>
		</xsl:variable>
		<xsl:variable name="uniqueHeadTuple">
			<xsl:copy-of select="msxsl:node-set($keypoolnodes)/htuple[not(.=following::htuple/.)]"/>
		</xsl:variable>
		<xsl:variable name="uniqueTuples">
			<xsl:copy-of select="msxsl:node-set($keypoolnodes)/tuple[not(.=following::tuple/.)]"/>
		</xsl:variable>
		<xsl:variable name="cleanedKeyPool">
			<xsl:for-each select="msxsl:node-set($uniqueHeadTuple)/node()">
				<xsl:value-of select="current()"/>
			</xsl:for-each>
			<xsl:for-each select="msxsl:node-set($uniqueTuples)/node()">
				<xsl:value-of select="current()"/>
			</xsl:for-each>
		</xsl:variable>
		<xsl:if test="current()">
			<xsl:choose>
				<xsl:when test="$uniqueHeadTuple != ''">
					<xsl:apply-templates select="current()">
						<xsl:with-param name="KeyPool" select="$cleanedKeyPool"/>
						<xsl:with-param name="parentElement" select="$parentElement"/>
					</xsl:apply-templates>
				</xsl:when>
				<xsl:otherwise>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>
	<xsl:template name="postevalkeypool">
		<xsl:param name="KeyPoolSnippet"/>
		<xsl:param name="localname"/>
		<xsl:choose>
			<xsl:when test="contains($KeyPoolSnippet, '§')">
				<xsl:call-template name="postevalkeypoolpairs">
					<xsl:with-param name="KeyPoolSnippet" select="substring-before($KeyPoolSnippet, '§')"/>
					<xsl:with-param name="localname" select="$localname"/>
				</xsl:call-template>
				<xsl:call-template name="postevalkeypool">
					<xsl:with-param name="KeyPoolSnippet" select="substring-after($KeyPoolSnippet, '§')"/>
					<xsl:with-param name="localname" select="$localname"/>
				</xsl:call-template>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="postevalkeypoolpairs">
		<xsl:param name="localname"/>
		<xsl:param name="KeyPoolSnippet"/>
		<xsl:choose>
			<xsl:when test="contains($KeyPoolSnippet, concat(concat($localname, ' '),'Sim')) and not(contains(substring-after($KeyPoolSnippet, ' Sim'), '.'))">
				<htuple>
					<xsl:value-of select="concat(normalize-space($KeyPoolSnippet), '§')"/>
				</htuple>
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="contains($KeyPoolSnippet, concat(' ','Sim'))">
					<xsl:variable name="hasdesignatedvalue">
						<xsl:variable name="getSimModelColumn">
							<xsl:value-of select="substring-after($KeyPoolSnippet, ' Sim')"/>
						</xsl:variable>
						<xsl:choose>
							<xsl:when test="contains(substring-after($getSimModelColumn,'.'), '.')">TRUE</xsl:when>
							<xsl:otherwise>FALSE</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<xsl:variable name="evalcurrentvalue">
						<xsl:choose>
							<xsl:when test="$hasdesignatedvalue = 'TRUE'">
								<xsl:variable name="check_value_of_property">
									<xsl:call-template name="GenerateTargetElementContentsFromSourceProperties">
										<xsl:with-param name="KeyPool" select="concat($KeyPoolSnippet, '§')"/>
										<xsl:with-param name="preEvaluation" select="substring-after(substring-before($KeyPoolSnippet, ' Sim'), concat($localname, '.'))"/>
									</xsl:call-template>
								</xsl:variable>
								<xsl:choose>
									<xsl:when test="$check_value_of_property = 'TRUE'">TRUE</xsl:when>
									<xsl:otherwise>FALSE</xsl:otherwise>
								</xsl:choose>
							</xsl:when>
							<xsl:otherwise>FALSE</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<xsl:if test="$hasdesignatedvalue = 'FALSE' or ($hasdesignatedvalue = 'TRUE' and $evalcurrentvalue = 'TRUE')">
						<tuple>
							<xsl:choose>
								<xsl:when test="contains(substring-after($KeyPoolSnippet, ' '), ' ')">
									<xsl:call-template name="getTuple">
										<xsl:with-param name="KeyPoolSnippet" select="$KeyPoolSnippet"/>
									</xsl:call-template>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat(normalize-space($KeyPoolSnippet), '§')"/>
								</xsl:otherwise>
							</xsl:choose>
						</tuple>
					</xsl:if>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="getTuple">
		<xsl:param name="KeyPoolSnippet"/>
		<xsl:if test="contains($KeyPoolSnippet, ' ') and (not(starts-with(substring-after($KeyPoolSnippet, ' '),'Sim')) or not(starts-with(substring-after($KeyPoolSnippet, ' '),'sim')))">
			<xsl:call-template name="getTuple">
				<xsl:with-param name="KeyPoolSnippet" select="substring-after($KeyPoolSnippet, ' ')"/>
			</xsl:call-template>
		</xsl:if>
		<xsl:if test="contains($KeyPoolSnippet, ' ') and (starts-with(substring-after($KeyPoolSnippet, ' '),'Sim') or starts-with(substring-after($KeyPoolSnippet, ' '),'sim'))">
			<xsl:copy-of select="concat(normalize-space($KeyPoolSnippet), '§')"/>
		</xsl:if>
	</xsl:template></xsl:stylesheet>