HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: //var/opt/OV/conf/agtrep/ServiceXML2CITransformerUtils.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!--  resolve key from key format -->
	<xsl:template name="resolveKey">
		<xsl:param name="ciIdFmt" />
		<xsl:choose>
			<xsl:when test="contains($ciIdFmt, '$')">
				<xsl:variable name="strInitial"
					select="substring-before($ciIdFmt, '$')" />
				<xsl:variable name="attr"
					select="substring-before(substring-after($ciIdFmt, '$'), '$')" />
				<xsl:variable name="strRemaining"
					select="substring($ciIdFmt,string-length(concat($attr,$strInitial))+3)" />
				<xsl:value-of select="$strInitial" />
				<xsl:variable name="attrResolv">
					<xsl:value-of
						select="Attributes/Attribute[@name=$attr]/@value" />
				</xsl:variable>
				<xsl:choose>
					<xsl:when
						test="string-length($attrResolv) = 0 and $attr='Location'">
						<xsl:value-of select="$nodename" />
					</xsl:when>
					<xsl:when
						test="string-length($attrResolv) &gt; 0">
						<xsl:value-of select="$attrResolv" />
					</xsl:when>
					<xsl:when
						test="string-length($attrResolv) = 0 and $attr != 'Location'">
						<xsl:value-of select="concat('$', $attr, '$')" />
					</xsl:when>
				</xsl:choose>
				<xsl:call-template name="resolveKey">
					<xsl:with-param name="ciIdFmt"
						select="$strRemaining" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$ciIdFmt" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!--  Get Key Format given Std -->
	<xsl:template name="getKey">
		<xsl:param name="cid" />
		<xsl:variable name="keyFmt"
			select="document($policyFile)//configuration/cid[key=normalize-space($cid)]/ci_identifier_format" />
		<xsl:call-template name="resolveKey">
			<xsl:with-param name="ciIdFmt" select="$keyFmt" />
		</xsl:call-template>
	</xsl:template>

	<!--  Create managed node entities -->
	<xsl:template name="createOrDeleteManagedNode">
		<xsl:variable name="contents">
			<id>
				<xsl:choose>
					<xsl:when test="string-length(Key) != 0">
						<xsl:value-of select="Key" />
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="getKey">
							<xsl:with-param name="cid" select="Std" />
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</id>
			<xsl:choose>
				<xsl:when test="string-length(NodeGuid) != 0">
					<coreid>
						<xsl:value-of select="NodeGuid" />
					</coreid>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="count(Virtual) = 0">
						<coreid>
							<xsl:value-of select="$coreid" />
						</coreid>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
			<name />
			<definition>
				<xsl:value-of select="Std" />
			</definition>
			<props>
				<xsl:if test="count(Virtual) != 0">
					<xsl:element name="virtual" />
				</xsl:if>
				<xsl:call-template name="convertAttributesToProps" />
				<xsl:if
					test="count(Attributes/Attribute[@name='location']) = 0">
					<xsl:element name="location">
 					        <xsl:attribute name="datatype" >
						  <xsl:text>string</xsl:text>
					        </xsl:attribute>
						<xsl:value-of select="$nodename" />
					</xsl:element>
				</xsl:if>
			</props>
			<type />
		</xsl:variable>
		<xsl:if test="name()='NewInstance'">
			<ci>
				<xsl:if test="@ref">
					<xsl:attribute name="ref">
						<xsl:value-of select="@ref" />
					</xsl:attribute>
				</xsl:if>
				<xsl:copy-of select="$contents" />
			</ci>
		</xsl:if>
		<xsl:if test="name()='DeleteInstance'">
			<deletedCi>
				<xsl:if test="@ref">
					<xsl:attribute name="ref">
						<xsl:value-of select="@ref" />
					</xsl:attribute>
				</xsl:if>
				<xsl:copy-of select="$contents" />
			</deletedCi>
		</xsl:if>
	</xsl:template>

	<!--  Create relationship entities -->
	<xsl:template name="createOrDeleteRelationship">
		<xsl:variable name="from">
			<xsl:for-each select="Parent/Instance">
				<xsl:element name="from">
					<xsl:if test="Virtual">
						<xsl:attribute name="virtual">
							<xsl:text>yes</xsl:text>
						</xsl:attribute>
					</xsl:if>
					<xsl:choose>
						<xsl:when test="@ref">
							<xsl:attribute name="ref">
								<xsl:value-of select="@ref" />
							</xsl:attribute>
						</xsl:when>
						<xsl:when test="string-length(Key)!=0">
							<xsl:value-of select="Key" />
							<xsl:if
								test="substring(Key, string-length(Key) - 1) = '@@'">
								<xsl:choose>
									<xsl:when
										test="string-length(NodeGuid) = 0">
										<xsl:value-of select="$coreid" />
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="NodeGuid" />
									</xsl:otherwise>
								</xsl:choose>
							</xsl:if>
							<xsl:text>,</xsl:text>
							<xsl:value-of select="Std" />
						</xsl:when>
						<xsl:when
							test="string-length(Std)!=0 and string-length(Key)=0">
							<xsl:variable name="keyObtained">
								<xsl:call-template name="getKey">
									<xsl:with-param name="cid"
										select="Std" />
								</xsl:call-template>
							</xsl:variable>
							<xsl:choose>
								<xsl:when
									test="substring($keyObtained, string-length($keyObtained) - 1) = '@@'">
									<xsl:choose>
										<xsl:when
											test="string-length(NodeGuid) = 0">
											<xsl:value-of
												select="concat($keyObtained,$coreid)" />
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of
												select="NodeGuid" />
										</xsl:otherwise>
									</xsl:choose>
									<xsl:text>,</xsl:text>
									<xsl:value-of select="Std" />
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$keyObtained" />
									<xsl:text>,</xsl:text>
									<xsl:value-of select="Std" />
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
					</xsl:choose>
				</xsl:element>
			</xsl:for-each>
		</xsl:variable>
		<xsl:for-each
			select="Components/Instance|DependentOn/Instance">
			<xsl:variable name="contents">
				<xsl:copy-of select="$from" />
				<xsl:element name="to">
					<xsl:choose>
						<xsl:when test="@ref">
							<xsl:attribute name="ref">
								<xsl:value-of select="@ref" />
							</xsl:attribute>
						</xsl:when>
						<xsl:when test="string-length(Key)!=0">
							<xsl:value-of select="Key" />
							<xsl:if
								test="substring(Key, string-length(Key) - 1) = '@@'">
								<xsl:choose>
									<xsl:when
										test="string-length(NodeGuid) = 0">
										<xsl:value-of select="$coreid" />
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="NodeGuid" />
									</xsl:otherwise>
								</xsl:choose>
							</xsl:if>
							<xsl:text>,</xsl:text>
							<xsl:value-of select="Std" />
						</xsl:when>
						<xsl:when
							test="string-length(Std)!=0 and string-length(Key)=0">
							<xsl:variable name="keyObtained">
								<xsl:call-template name="getKey">
									<xsl:with-param name="cid"
										select="Std" />
								</xsl:call-template>
							</xsl:variable>
							<xsl:choose>
								<xsl:when
									test="substring($keyObtained, string-length($keyObtained) - 1) = '@@'">
									<xsl:choose>
										<xsl:when
											test="string-length(NodeGuid) = 0">
											<xsl:value-of
												select="concat($keyObtained,$coreid)" />
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of
												select="NodeGuid" />
										</xsl:otherwise>
									</xsl:choose>
									<xsl:text>,</xsl:text>
									<xsl:value-of select="Std" />
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$keyObtained" />
									<xsl:text>,</xsl:text>
									<xsl:value-of select="Std" />
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
					</xsl:choose>
				</xsl:element>
				<xsl:if test="parent::Components">
					<xsl:element name="relationshipType">
						<xsl:text>contains</xsl:text>
					</xsl:element>
				</xsl:if>
				<xsl:if test="parent::DependentOn">
					<xsl:element name="relationshipType">
						<xsl:text>dependson</xsl:text>
					</xsl:element>
				</xsl:if>
			</xsl:variable>
			<xsl:if test="ancestor::NewRelationship">
				<relationship>
					<xsl:copy-of select="$contents" />
				</relationship>
			</xsl:if>
			<xsl:if test="ancestor::DeleteRelationship">
				<deletedRelationship>
					<xsl:copy-of select="$contents" />
				</deletedRelationship>
			</xsl:if>
		</xsl:for-each>
		<xsl:for-each
			select="GenericRelations/Relations">
			<xsl:variable name="reltype">
                          <xsl:value-of select="@type" />
			</xsl:variable>
			<xsl:for-each select="./Instance">
			<xsl:variable name="contents">
				<xsl:copy-of select="$from" />
				<xsl:element name="to">
					<xsl:choose>
						<xsl:when test="@ref">
							<xsl:attribute name="ref">
								<xsl:value-of select="@ref" />
							</xsl:attribute>
						</xsl:when>
						<xsl:when test="string-length(Key)!=0">
							<xsl:value-of select="Key" />
							<xsl:if
								test="substring(Key, string-length(Key) - 1) = '@@'">
								<xsl:choose>
									<xsl:when
										test="string-length(NodeGuid) = 0">
										<xsl:value-of select="$coreid" />
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="NodeGuid" />
									</xsl:otherwise>
								</xsl:choose>
							</xsl:if>
							<xsl:text>,</xsl:text>
							<xsl:value-of select="Std" />
						</xsl:when>
						<xsl:when
							test="string-length(Std)!=0 and string-length(Key)=0">
							<xsl:variable name="keyObtained">
								<xsl:call-template name="getKey">
									<xsl:with-param name="cid"
										select="Std" />
								</xsl:call-template>
							</xsl:variable>
							<xsl:choose>
								<xsl:when
									test="substring($keyObtained, string-length($keyObtained) - 1) = '@@'">
									<xsl:choose>
										<xsl:when
											test="string-length(NodeGuid) = 0">
											<xsl:value-of
												select="concat($keyObtained,$coreid)" />
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of
												select="NodeGuid" />
										</xsl:otherwise>
									</xsl:choose>
									<xsl:text>,</xsl:text>
									<xsl:value-of select="Std" />
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="$keyObtained" />
									<xsl:text>,</xsl:text>
									<xsl:value-of select="Std" />
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
					</xsl:choose>
				</xsl:element>
				<xsl:element name="relationshipType">
				  <xsl:attribute name="realType">
				   <xsl:value-of select="$reltype" />
				  </xsl:attribute>
				  <xsl:text>contains</xsl:text>
				</xsl:element>
			</xsl:variable>
			<xsl:if test="ancestor::NewRelationship">
				<relationship>
					<xsl:copy-of select="$contents" />
				</relationship>
			</xsl:if>
			<xsl:if test="ancestor::DeleteRelationship">
				<deletedRelationship>
					<xsl:copy-of select="$contents" />
				</deletedRelationship>
			</xsl:if>
		   </xsl:for-each>
		</xsl:for-each>
	</xsl:template>

	<!--  Create Attribute entities of form <AttributeName Type="bla">Value</AttributeName> -->
	<xsl:template name="convertAttributesToProps">
		<xsl:for-each select="Attributes/Attribute">
			<xsl:variable name="name" select="@name" />
			<xsl:variable name="value" select="@value" />
			<xsl:variable name="datatype" select="@datatype" />
			<xsl:element name="{$name}">
                        <xsl:attribute name="datatype">
                         <xsl:choose>
                          <xsl:when test="$datatype">
                            <xsl:value-of select="$datatype" />
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:text>string</xsl:text>
                          </xsl:otherwise>
                         </xsl:choose>
                        </xsl:attribute>
		        <xsl:value-of select="$value" />
			</xsl:element>
		</xsl:for-each>
	</xsl:template>

</xsl:stylesheet>