Hi,
I have some requirement which is explained below.
The input XML is something like:
<item>
<body>
<blocks>
<block>
<userDefinedFields>
<userDefinedField>
<fieldLabel>KOBAR</fieldLabel>
<fieldDisplayLabel>Global KO</fieldDisplayLabel>
<fieldValue>0</fieldValue>
<fieldType>numeric</fieldType>
</userDefinedField>
<userDefinedField>
<fieldLabel>KIBAR</fieldLabel>
<fieldDisplayLabel>Global KI</fieldDisplayLabel>
<fieldValue>50</fieldValue>
<fieldType>numeric</fieldType>
</userDefinedField>
<userDefinedField>
<fieldLabel>BSWP</fieldLabel>
<fieldDisplayLabel>Global SW</fieldDisplayLabel>
<fieldValue>1</fieldValue>
<fieldType>integer</fieldType>
</userDefinedField>
</userDefinedFields>
<otherFields>
<otherField/>
</otherFields>
<userDefinedFields>
<userDefinedField>
<fieldLabel>EXCLN</fieldLabel>
<fieldDisplayLabel>Exclude N</fieldDisplayLabel>
<fieldValue>1</fieldValue>
<fieldType>integer</fieldType>
</userDefinedField>
<userDefinedField>
<fieldLabel>ASTDT</fieldLabel>
<fieldDisplayLabel>Start</fieldDisplayLabel>
<fieldValue>25</fieldValue>
<fieldType>integer</fieldType>
</userDefinedField>
</userDefinedFields>
</block>
</blocks>
</body>
</item>
Requirement:
If the 'userDefinedField' with 'fieldLabel' BSWP exists, then pick the 'fieldValue' of 'userDefinedField' with 'fieldLabel' ASTDT
XSL Code:
I tried with the below shown XSL, but it's not giving the desired output. Can anybody please help if something is going wrong in the code. Thanks for your time.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:apply-templates select="item/body/blocks/block/userDefinedFields/userDefinedField" />
</xsl:template>
<xsl:template match="userDefinedField">
<xsl:if test="./fieldLabel='BSWP'">
<xsl:value-of select="self::node[fieldLabel='ASTDT']/fieldValue" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
My idea in writing the above code is: as we are inside the template matching 'userDefinedField', I am checking for fieldLabel=BSWP and if it exists then pick the 'fieldValue' where fieldLabel=ASTDT. But this code is returning blank value.