In XSLT 2.0, can we use if then only means no else clause.
<Employee><Status><xsl:value-of select="if (tns:Employee/tns:EmpId = 4) then 'new' else 'old'"/></Status></Employee>
Here if I don't want else clause, means if empid is not 4, then do not populate Status field. what will be xslt?
Asked
Active
Viewed 1,929 times
0

user3480752
- 1
- 2
-
Well, after Googling it and thinkng it over: what *would* the value be if there is no `else`? Reorder things to avoid the situation. – Jongware Apr 14 '15 at 19:17
-
By "don't populate the status field" do you mean you want an empty `
` or do you want no Status element at all? – Ian Roberts Apr 14 '15 at 19:37 -
1What's the connection to yor [previous question](http://stackoverflow.com/q/29633276/1987598)? Why do you ask very similar questions with a different XML input? Also, some of your older questions need your attention: http://stackoverflow.com/q/29633276/1987598, http://stackoverflow.com/q/22759983/1987598 and http://stackoverflow.com/q/24752681/1987598. Either accept an answer to them or otherwise react to the answers given. – Mathias Müller Apr 14 '15 at 20:29
-
I want no Status element at all. – user3480752 Apr 15 '15 at 11:08
2 Answers
2
Unless I'm reading the question wrong, just add an empty string or empty sequence.
Example...
if (tns:Employee/tns:EmpId = 4) then 'new' else ''
or
if (tns:Employee/tns:EmpId = 4) then 'new' else ()

Daniel Haley
- 51,389
- 6
- 69
- 95
-
Thanks for your reply.This will create
but if I need not to create the status field what will be the solution. – user3480752 Apr 15 '15 at 11:08 -
@user3480752 - If you don't want a status element output at all you can use an xsl:if like suggested by Tim C or you might be able to narrow the original scope of what you're processing. It's hard to give an example though when your question does not contain a complete example of your XSLT. – Daniel Haley Apr 15 '15 at 13:35
1
If you don't want any status
at all, you can easily achieve this with the standard xsl:if
in XSLT (available in all versions)
<Employee>
<xsl:if test="tns:Employee/tns:EmpId = 4">
<Status>new</Status>
</xsl:if>
</Employee>

Tim C
- 70,053
- 14
- 74
- 93