xml input
<?xml version="1.0" encoding="UTF-8"?>
<p:transformOutput xmlns:p="http://test/export/objects">
<p:objectSet>
<p:objects>
<p:object>
<p:objectAttributes>
<p:objectType>a</p:objectType>
<p:attribute name="x">F600</p:attribute>
<p:attribute name="y">A100</p:attribute>
<p:attribute name="z">D400</p:attribute>
</p:objectAttributes>
</p:object>
<p:object>
<p:objectAttributes>
<p:objectType>b</p:objectType>
<p:attribute name="x">F600</p:attribute>
<p:attribute name="y">C300</p:attribute>
<p:attribute name="z">B200</p:attribute>
<p:attribute name="T">20</p:attribute>
</p:objectAttributes>
</p:object>
<p:object>
<p:objectAttributes>
<p:objectType>b</p:objectType>
<p:attribute name="x">a</p:attribute>
<p:attribute name="y">A100</p:attribute>
<p:attribute name="z">B200</p:attribute>
<p:attribute name="T">40</p:attribute>
</p:objectAttributes>
</p:object>
</p:objects>
</p:objectSet>
</p:transformOutput>
xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR" xmlns:p="http://test/export/objects"
exclude-result-prefixes="p">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/p:transformOutput/p:objectSet">
<test:xml-tables xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:test="http://ift.tt/1tjObns">
<xsl:for-each select="p:objects/p:object">
<xsl:element name="test:{p:objectType}">
<xsl:for-each select="p:objectAttributes/p:attribute">
<xsl:element name="test:{@name}">
<xsl:value-of select="text()" />
</xsl:element>
</xsl:for-each>
<xsl:variable name="attributes" select="p:objectAttributes/*" />
<xsl:variable name="matching-template"
select="document('templates.xml')/Templates/Template[System_Table=$attributes]" />
<xsl:element name="test:{$matching-template/System_Attribute}">
<xsl:for-each select="p:objectType">
<!-- <xsl:copy-of select="$matching-template/System_Attribute"/> -->
<xsl:value-of select="$matching-template/System_Value" />
<!-- <xsl:copy-of select="$matching-template/System_Value"/> -->
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:for-each>
</test:xml-tables>
</xsl:template>
</xsl:stylesheet>
Look up xml
<?xml version="1.0"?>
<Templates>
<Template>
<System_Class>a</System_Class>
<System_Table>A100</System_Table>
<System_Attribute>aA</System_Attribute>
<System_Value>200</System_Value>
</Template>
<Template>
<System_Class>b</System_Class>
<System_Table>B200</System_Table>
<System_Attribute>bB</System_Attribute>
<System_Value>200</System_Value>
</Template>
<Template>
<System_Class>b</System_Class>
<System_Table>B200</System_Table>
<System_Attribute>bB</System_Attribute>
<System_Value>200</System_Value>
</Template>
<Template>
<System_Class>b</System_Class>
<System_Table>B200</System_Table>
<System_Attribute>85</System_Attribute>
<System_Value>200</System_Value>
</Template>
<Template>
<System_Class>b</System_Class>
<System_Table>B200</System_Table>
<System_Attribute>bB</System_Attribute>
<System_Value>200</System_Value>
<condition>T=40 or T =20</condition>
</Template>
<Template>
<System_Class>b</System_Class>
<System_Table>B200</System_Table>
<System_Attribute>bB</System_Attribute>
<System_Value>200</System_Value>
<condition>T=40</condition>
</Template>
<Template>
<System_Class>b</System_Class>
<System_Table>B200</System_Table>
<System_Attribute>bB</System_Attribute>
<System_Value>200</System_Value>
<condition>T!=40</condition>
</Template>
</Templates>
The transformation works fine if there is no condition attribute in xml look up. I just want to evaluate the condition in the lookup xml and the input xml. For example T=20 will be evaluated if only T=20 in the input file
if the condition is true, get the System Attribute and System Value. if false, don't execute the template. for example if the attribute doesn't exist, we are just comparing if the system_class and System_table match the xml input. If the condition attribute exisit we campare the System_class, System_table and the condition attirbute
No comments:
Post a Comment