locked
control object not worked RRS feed

  • Question

  • I am writing an XSLT that will format events for HTML email distribution. One of the event data properties is defined as nvarchar(max). This column contains text formatted with CRs. I need to replace the CRs with <br/> for HTML email. I use the following snippet.

    <xsl:template match="notification">
      <p>
        <xsl:call-template name="line-breaks">
          <xsl:with-param name="text" select="UpdateDescription"/>
        </xsl:call-template>
      </p>
    </xsl:template>

    <xsl:template name="line-breaks">
      <xsl:param name="text"/>
      <xsl:choose>
        <xsl:when test="contains($text,'&#13;')">
          <xsl:value-of select="substring-before($text,'&#13;')"/>
          <br/>
          <xsl:call-template name="line-breaks">
            <xsl:with-param name="text"  select="substring-after($text,'&#13;')"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$text"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    I am trying to figure out why this isn't working. If I set the format of the email to text, the CRs appear correctly, and the data looks fine, so I know that the control characters are there. I've used the template with other formatted data in the past (for a web page display), so I know the code is fine. In testing, the contains clause never returns true, which is odd. My question is, does Notification Services do something to the data that would cause the line-breaks template to break?

    Saturday, October 20, 2012 8:28 AM

Answers

  • <xsl:template match="notification">

      <p>
        <xsl:call-template name="line-breaks">
          <xsl:with-param name="text" select="UpdateDescription"/>
        </xsl:call-template>
      </p>
    </xsl:template>

    <xsl:template name="line-breaks">
      <xsl:param name="text"/>
      <xsl:choose>
        <xsl:when test="contains($text,'&#13;')">
          <xsl:value-of select="substring-before($text,'&#13;')"/>
          <br/>
          <xsl:call-template name="line-breaks">
            <xsl:with-param name="text"  select="substring-after($text,'&#13;')"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$text"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    Hi Torres,

    Use the LF character (character 10) instead of 13 will solve your problem.

    Best Regards,
    Iric
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Iric Wen Monday, October 22, 2012 7:33 AM
    • Marked as answer by torres0319 Friday, October 26, 2012 5:03 PM
    Monday, October 22, 2012 7:32 AM