I am trying to select xml tag attribute values from lookup xml if at least two of the attributes match the actual xml file.



Here is the orginal xml file



<?xml version="1.0" encoding="UTF-8"?>
<p:transformOutput xmlns:p="http://cfpe/export/objects">
<p:objectSet>
<p:objects>
<p:object>
<p:objectAttributes>
<p:objectType>FNC</p:objectType>
<p:attribute name="ssc">10</p:attribute>
<p:attribute name="btc">0</p:attribute>
<p:attribute name="col">Fl(2+1) G</p:attribute>
<p:attribute name="ns2">53</p:attribute>
<p:attribute name="br2">13</p:attribute>
<p:attribute name="vrr">4</p:attribute>
<p:attribute name="object_code">BC020</p:attribute>
</p:objectAttributes>
</p:object>
</p:objects>
</p:objectSet>
</p:transformOutput>


Here is my is file look up xml 100 378 0 DNC ALL dangerp BD140 hdp NaN vrr!=4 100 378 0 DNC ALL dangerp BD140 hdp NaN vrr=4 or 2



<ObjTmplId>100</ObjTmplId>
<AttTmplId>378</AttTmplId>
<Is_Ingest>0</Is_Ingest>
<System_Name>DNC</System_Name>
<System_Category>ALL</System_Category>
<System_Class>dangerp</System_Class>
<System_Table>BD140</System_Table>
<System_Attribute>hdp</System_Attribute>
<System_Value>NaN</System_Value>

</Template>
</Templates>


I tried to use transformation for the above to xmls if System_Class and System_Table matches with the first xml values, output the rest of the attributes with the first xml file attributes. And also if there is a condition in the look up file, use output the attributes for that condition


Here is my xsl



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:p="http://cfpe/export/objects"
exclude-result-prefixes="p">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="objectPath" select="document('lookups.xml')/Templates"></xsl:variable>
<xsl:variable name="valuePath" select="p:transformOutput/p:objectSet/p:objects" />


<xsl:key name="template" match="Template" use="System_Class" />
<xsl:key name="template" match="Template" use= "System_Table" />

<xsl:template match="/p:transformOutput/p:objectSet">
<objects>
<xsl:for-each select="p:objects/p:object">
<xsl:variable name="objType" select="p:objectType" />

<xsl:variable name="matchFcode" select="p:objectAttributes/p:attribute/f_code" />
<object type="{$objType}">
<template>
<!-- switch context to the lookup file in order to use key -->
<xsl:for-each select="document('templates.xml')">
<xsl:copy-of select="key('template', $objType)/System_Value"/>
</xsl:for-each>
</template>
</object>
</xsl:for-each>
</objects>
</xsl:template>

</xsl:stylesheet>

No comments:

Post a Comment