I have the below condition that I have wriiten in xsl below..
as i have getting an value in xml of fpml:tradeId now it can be there in xml or it can not be there for example as shown below..
<fpml:tradeId tradeIdScheme=""></fpml:tradeId>
or it can contain value also
<fpml:tradeId tradeIdScheme="">10381159400</fpml:tradeId>
as advise i have change the implementation to but still not working ..
<xsl:if test = "fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId = ' '">
<xsl:value-of select="'null'" />
</xsl:if>
</ContractID>
so to deal with this problem i have come up with this below xsl , now the problem comes is that for the cases where tradeId is not there in xml it is not putting null string please advise is my below implementation of xsl is correct
<xsl:if test = "fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId != ' '">
<xsl:choose>
<xsl:when test="contains(fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId,'-')">
<xsl:value-of select="substring-before(fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId,'-')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test = "fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId = ' '">
<xsl:value-of select="'null'" />
</xsl:if>
</ContractID>
as advise new implemetaion done but it is still not working..
<xsl:if test="normalize-space(fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId)">
<xsl:choose>
<xsl:when test="contains(fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId,'-')">
<xsl:value-of select="substring-before(fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId,'-')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:if test = "fpml:dataDocument/*/*/fpml:partyTradeIdentifier[2]/fpml:tradeId = ' '">
<xsl:value-of select="'null'" />
</xsl:if>
</ContractID>
You're testing for
which it doesn't in your example - the value of your
fpml:tradeId
is the empty string, not a string containing a space. Instead of comparing the value against' '
for the first case you could use a test ofIn XPath a string coerces to a boolean by treating it as false if the string is empty and true if it isn't, so the test will pass if the
tradeId
value contains at least one non-whitespace character, and fail if it is completely empty or contains only whitespace.For the second case
would give you the reverse test - true if the string is all whitespace or empty, false if it isn't (or just use a
choose
with anotherwise
clause instead of two opposingif
tests).