I'm creating a Excel xml workbook via xslt. One of the date fields is often NULL and I need to not insert anything into the cell when this is the case. At the moment even though I'm not specifying anything the value -146087 is being entered into the cell. This is then displayed as hashes as the cell is date formatted.
What can I put between the
<xsl:otherwise></xsl:otherswise>
tags?
Here's the xslt...
<Cell>
<Data ss:Type="DateTime">
<xsl:choose>
<xsl:when test="substring(EOI_StartDate, 0, 11)">
<xsl:value-of select="substring(EOI_StartDate, 0, 11)"/>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</Data>
<NamedCell ss:Nam开发者_JAVA技巧e="_FilterDatabase"/>
</Cell>
It seems from your question that you want to produce:
<Data/>
in the case when the condition is not fulfilled.
The simplest way to do this is not to use <xsl:choose>
but the simpler <xsl:if>
:
<Data ss:Type="DateTime">
<xsl:if test="substring(EOI_StartDate, 0, 11)">
<xsl:value-of select="substring(EOI_StartDate, 0, 11)"/>
</xsl:if>
</Data>
Or, in case you want to omit the <Data>
element completely if the condition is not satisfied, then:
<xsl:if test="substring(EOI_StartDate, 0, 11)">
<Data ss:Type="DateTime">
<xsl:value-of select="substring(EOI_StartDate, 0, 11)"/>
</Data>
</xsl:if>
Finally, if the <Data>
element must stay there, but you don't want it to be treated as date if the condition is not satisfied, do this:
<xsl:choose>
<xsl:when test="substring(EOI_StartDate, 0, 11)">
<Data ss:Type="DateTime">
<xsl:value-of select="substring(EOI_StartDate, 0, 11)"/>
</Data>
</xsl:when>
<xsl:otherwise>
<Data ss:Type="String"> </Data>
</xsl:otherwise>
</xsl:choose>
精彩评论