Some of the attributes are in the /values have conditions in the /ComparsionList>. I was able to compare the object and title and get the output but couldn't output the desired output when there is a condition that depends on another value
Here below is my xmpl input
<?xml version="1.0" encoding="UTF-8"?>
<Types>
<Type>
<title> TestingOne</title>
<p:values>
<attribute name="vala">10</attribute>
<attribute name="valb">20</attribute>
<attribute name="valc">30</attribute>
<attribute name="vald">40</attribute>
</values>
<title> TestingTwo</title>
<p:values>
<attribute name="vala">10</attribute>
<attribute name="valb">20</attribute>
<attribute name="valc">15</attribute>
<attribute name="vald">45</attribute>
</values>
<title> TestingThree</title>
<p:values>
<attribute name="vala">78</attribute>
<attribute name="valb">20</attribute>
<attribute name="valc">60</attribute>
<attribute name="vald">42</attribute>
</values>
</Type>
<comparision>
<comparisionList>
<object>TestingOne</object>
<condition>valc=30</condition>
<newName>vald</newName>
<newValue>60</newValue>
</comparisionList>
<comparisionList>
<object>TestingTwo</object>
<condition>valb=40 or valb=20</condition>
<newName>vald</newName>
<newValue>60</newValue>
</comparisionList>
<comparisionList>
<object>TestingThree</object>
<newName>vale</newName>
<newValue>100</newValue>
</comparisionList>
</comparison>
</Types>
Here my xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/Types">
<objects>
<xsl:for-each select="/Type">
<xsl:for-each select="p:objectSet/p:objects/p:object">
<xsl:element name="{title}">
<xsl:for-each select="values/attribute">
<xsl:element name="{@name}">
<xsl:value-of select="text()"/>
</xsl:element>
</xsl:for-each>
<xsl:variable name="attributes" select="p:values/*"/>
<xsl:variable name="newPath" select="/Types/Type/ns1:Template[object=$attributes]"/>
<template>
<xsl:value-of select="$newPath/newName"/>
<xsl:value-of select="$newPath/newValue"/>
</template>
</object>
</xsl:for-each>
</objects>
</xsl:template>
</xsl:stylesheet>
Here is the expected output
<?xml version="1.0" encoding="UTF-8"?>
<OutPut>
<testingone>
<vala>10</vala>
<valb>20</valb>
<valc>30</valc>
<vald>60</vald>
</testingone>
<testingTwo>
<vala>10</vala>
<valb>20</valb>
<valc>15</valc>
<vald>60</vald>
</testingTwo>
<testingThree>
<vala>78</vala>
<valb>20</valb>
<valc>60</valc>
<vald>100</vald>
</testingThree>
</OutPut>
No comments:
Post a Comment