XML Transform is removing <br/> tags

Last post 07-22-2005 3:58 PM by codeurai. 3 replies.

Sort Posts:

  • XML Transform is removing <br/> tags

    07-22-2005, 12:53 PM
    • Member
      90 point Member
    • codeurai
    • Member since 01-12-2004, 7:17 AM
    • Stephenville Texas
    • Posts 18

    Why does transforming xml into html remove <br/> tags?

    For example a test xml document:

    <?xml version="1.0" encoding="utf-8" ?>
    <?xml-stylesheet type="text/xsl" href="archwayEmail.xslt"?>
    <
    archway issueId="35" title="Archway Update For Thursday, July 21, 2005" dateCompiled="7/21/2005 11:02:09 AM">
       <news id="154">
          <title>Test Title 1</title>
          <shortText>Some short text<br/>More short text</shortText>
       </news>
       <news id="155">
          
    <title>Test Title 2</title>
          <shortText>Some short text</shortText>
       </news>
    </archway>

    And the template:

    <?xml version="1.0" encoding="UTF-8"?>
    <
    xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <
    xsl:output method="html" encoding="UTF-8" standalone="yes" version="4.0" indent="yes" media-type="text/html" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd" />

    <!-- MAIN TEMPLATE -->
    <xsl:template match="/">
    <html>
    <body>
       <xsl:apply-templates select="//archway" />
       <p>News</p>
       <xsl:apply-templates select="//archway/news" />
    </body>
    </html>
    </xsl:template>

    <!-- ARCHWAY TEMPLATE -->
    <xsl:template match="archway">
       <p class="header"><xsl:value-of select="@title" /></p>
    </xsl:template>

    <!
    -- NEWS TEMPATE -->
    <xsl:template match="news">
       <p><xsl:value-of select="title" /></p>
       <p><xsl:value-of select="shortText" /></p>
    </xsl:template>

    </xsl:stylesheet>

    When the template is applied to the xml, the resulting html is fine with the exception that the <br/> tag in the shortText node of the first news node gets removed.

    I am using ASP with the MSxml2.DOMDocument.3.0 processor.

    Thanks for your help.

    Joe

  • Re: XML Transform is removing <br/> tags

    07-22-2005, 1:07 PM
    • Star
      13,635 point Star
    • master4eva
    • Member since 12-06-2002, 2:54 PM
    • Durban, South Africa
    • Posts 2,719
    When you output that node, instead of doing

    <xsl:value-of select="shortText"/>

    Use the following

    <xsl:text disable-output-escaping="yes">
       <xsl:value-of select="shortText"/>
    </xsl:text>
    -- Justin Lovell
  • Re: XML Transform is removing <br/> tags

    07-22-2005, 3:01 PM
    • Member
      90 point Member
    • codeurai
    • Member since 01-12-2004, 7:17 AM
    • Stephenville Texas
    • Posts 18

    Thanks for the reply, but when I try that I get a parse error

    Keyword xsl:text may not contain xsl:value-of.

    ???

  • Re: XML Transform is removing <br/> tags

    07-22-2005, 3:58 PM
    • Member
      90 point Member
    • codeurai
    • Member since 01-12-2004, 7:17 AM
    • Stephenville Texas
    • Posts 18

    Well if anyone is interested, I found a way to keep the tags.
    instead of doing a <xsl:value-of select="something" />
    use a <xsl:copy-of select="something" />

    Big Smile [:D]

    Thanks for the help.

    Joe

Page 1 of 1 (4 items)