I'm transforming one XML file to another XML format.
Here is sample source file:
<xml>
<title>Pride and Prejudice</title>
<subtitle>Love Novel</subtitle>
</xml>
And here is xsl file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Product>
<xsl:apply-templates/>
</Product>
</xsl:template>
<xsl:template match="title">
<TitleDetail>
<TitleType>01</TitleType>
<TitleElement>
<TitleElementLevel>01</TitleElementLevel>
<TitleText><xsl:value-of select="current()"/></TitleText>
<!--Here Problem!!!-->
<xsl:if test="subtitle">
<Subtitle>123</Subtitle>
</xsl:if>
</TitleElement>
</TitleDetail>
</xsl:template>
Idea is that if source file contains subtitle tag I need to insert "Subtitle" node to the "TitleDetail", but 'if' condition returns false. How to check if source file has subtitle information?