I am having much difficulty trying to operate on a variable value using when test=....
When I output $tcbrand it outputs 'Direct' but when I operate on it, it returns false and hits the otherwise block. What am I doing wrong?
<fo:static-content flow-name="header-normal" font-size="10pt">
<xsl:variable name="tcbrand" select="smf:entity[@type='d2501b79-f888-4aa8-9fcf-a667a4c47c84']"/>
<fo:block font-size="10pt" text-align="left">
<fo:inline font-weight="normal">Brand: <xsl:value-of select="$tcbrand"/></fo:inline>
</fo:block>
<xsl:choose>
<!--<xsl:if test="$image = 'hello' ">-->
<xsl:when test="string($tcbrand)='Direct'">
<fo:block text-align="right" space-before="0mm">
<fo:external-graphic src="url('C:\Program Files (x86)\numerointeractive\whitemail\Images\18-30.png')" />
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block text-align="right" space-before="0mm">
<fo:external-graphic src="url('C:\Program Files (x86)\numerointeractive\whitemail\Images\ecom2.jpg')" />
</fo:block>
</xsl:otherwise>
</xsl:choose>
This is the xml that gets generated, which I am operating on:
<smf:entity id="48659" type="d2501b79-f888-4aa8-9fcf-a667a4c47c84" confidence="1.0" author="2e0b99b3-9cba-4736-a59b-fe00b5f62871" validated="true" preferred="false" requiresComponentExtraction="false" changeTime="2012-11-26T14:47:28.840Z" nonPersistedId="false" modified="false">
<smf:value>Direct</smf:value>
</smf:entity>
will set the
tcbrandvariable to thesmf:entityelement. The string value of an element is the concatenation of all its descendant text nodes, which formeans a newline, seven spaces, “Direct”, another newline, and another four spaces. This is not equal to “Direct”. I can think of three possible fixes: you could use
at the top of your stylesheet, which will cause it to completely ignore all whitespace-only text nodes in the input document, you could
normalize-spacewhen doing the test:or you could take the value of the child
<smf:value>element instead of the parent<smf:entity>one, either at the variable declaration pointor at the point of the test