EDN Admin
Well-known member
Hi,
Here is my input xml:
<profile>
<bikes>
<bike>simple</bike>
<bike>Bike1</bike>
<bike>Bike3</bike>
<bike>Bike4</bike>
<bike>hybrid</bike>
</bikes>
</profile>
Well, its not really the exact input. "hybrid" may or may not be present.
And I used this xslt:
<xsl:template match="profile/bikes
<Rule propName="BikeType
<xsl:for-each select="bike
<xsl:if test=".=simple>
<SupportedValue value="AAA" />
</xsl:if>
<xsl:if test=".=bike1>
<SupportedValue value="BBB" />
</xsl:if>
<xsl:if test=".=bike2>
<SupportedValue value="CCC" />
</xsl:if>
<xsl:if test=".=bike3>
<SupportedValue value="DDD" />
</xsl:if>
<xsl:if test=".=bike4>
<SupportedValue value="EEE" />
</xsl:if>
<xsl:if test=".=hybrid>
<SupportedValue value="Custom" />
</xsl:if>
</xsl:for-each>
</Rule>
</xsl:template>
Heres how my output was:
<Rule propName="BikeType
<SupportedValue value="AAA" />
<SupportedValue value="BBB" />
<SupportedValue value="DDD" />
<SupportedValue value="EEE" />
<SupportedValue value="Custom" />
</Rule>
But my requirement got changed now. Heres the input xml:
<profile>
<bikes>
<bike>simple</bike>
<bike>Bike1</bike>
<bike>Bike3</bike>
<bike>Bike4</bike>
<bike>hybrid</bike>
</bikes>
<HybridMinWeight> 101 </HybridMinWeight>
<HybridMaxWeight> 153 </HybridMaxWeight>
<HybridMinHeight> 132 </HybridMinHeight>
<HybridMaxHeight> 143 </HybridMaxHeight>
</profile>
The extra elements would come only when "hybrid" is present.
And heres how my output should look like:
<Rule propName="BikeType
<SupportedValue value="AAA" />
<SupportedValue value="BBB" />
<SupportedValue value="DDD" />
<SupportedValue value="EEE" />
<SupportedValue value="Custom" />
</Rule>
<Rule propName="CustomWeightRange
<supportedRange lower="101" upper="153"/>
</Rule>
<Rule propName="CustomHeightRange
<supportedRange lower="132" upper="143"/>
</Rule>
Any ideas?
Thanks and Regards,
krishna
View the full article
Here is my input xml:
<profile>
<bikes>
<bike>simple</bike>
<bike>Bike1</bike>
<bike>Bike3</bike>
<bike>Bike4</bike>
<bike>hybrid</bike>
</bikes>
</profile>
Well, its not really the exact input. "hybrid" may or may not be present.
And I used this xslt:
<xsl:template match="profile/bikes
<Rule propName="BikeType
<xsl:for-each select="bike
<xsl:if test=".=simple>
<SupportedValue value="AAA" />
</xsl:if>
<xsl:if test=".=bike1>
<SupportedValue value="BBB" />
</xsl:if>
<xsl:if test=".=bike2>
<SupportedValue value="CCC" />
</xsl:if>
<xsl:if test=".=bike3>
<SupportedValue value="DDD" />
</xsl:if>
<xsl:if test=".=bike4>
<SupportedValue value="EEE" />
</xsl:if>
<xsl:if test=".=hybrid>
<SupportedValue value="Custom" />
</xsl:if>
</xsl:for-each>
</Rule>
</xsl:template>
Heres how my output was:
<Rule propName="BikeType
<SupportedValue value="AAA" />
<SupportedValue value="BBB" />
<SupportedValue value="DDD" />
<SupportedValue value="EEE" />
<SupportedValue value="Custom" />
</Rule>
But my requirement got changed now. Heres the input xml:
<profile>
<bikes>
<bike>simple</bike>
<bike>Bike1</bike>
<bike>Bike3</bike>
<bike>Bike4</bike>
<bike>hybrid</bike>
</bikes>
<HybridMinWeight> 101 </HybridMinWeight>
<HybridMaxWeight> 153 </HybridMaxWeight>
<HybridMinHeight> 132 </HybridMinHeight>
<HybridMaxHeight> 143 </HybridMaxHeight>
</profile>
The extra elements would come only when "hybrid" is present.
And heres how my output should look like:
<Rule propName="BikeType
<SupportedValue value="AAA" />
<SupportedValue value="BBB" />
<SupportedValue value="DDD" />
<SupportedValue value="EEE" />
<SupportedValue value="Custom" />
</Rule>
<Rule propName="CustomWeightRange
<supportedRange lower="101" upper="153"/>
</Rule>
<Rule propName="CustomHeightRange
<supportedRange lower="132" upper="143"/>
</Rule>
Any ideas?
Thanks and Regards,
krishna
View the full article