XSLT - Turns <br/> into <br> ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JoeS
    New Member
    • Jul 2007
    • 4

    XSLT - Turns <br/> into <br> ?

    I'm new to XSLT, it what our old website developer used but he has now left our company. I have been given the task of making our site output as valid XHTML as I can get it. Currently in the .XSL files I write self-closing tags like <br/> but in the output XHTML they come out as <br> and therefore the page doesn't validate. This happens for other self-closing tags like <img src=""/> too.

    I don't really know XSLT so I don't know how I can fix this from happening. Any suggestions?!
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    What xslt processor or process are you using?
    Do you have an
    <xsl:output> tag at the beginning, and if so, are you setting type="html" as opposed to "xml" or "xhtml"?

    Comment

    • JoeS
      New Member
      • Jul 2007
      • 4

      #3
      Perfect - I changed it to 'xhtml' and it now outputs self-closing tags. Thanks you :)

      One slight problem that's occuring now though - in the XSL there are these lines:

      Code:
      <!-- start the stylesheet -->
      <xsl:template match="/">
      	<xsl:apply-templates select="XML"/>
      </xsl:template>
      
      <!-- xml tempate -->
      <xsl:template match="XML">
      
      <p>test</p>


      This is now causing this line to appear in my XHTML:

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      <p>test<p/>
      I'm sure this shouldn't be there?

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        If you don't want it in there, then remove those lines. Or are you talking about the xml type declaration?

        Comment

        • JoeS
          New Member
          • Jul 2007
          • 4

          #5
          yes this part shouldn't be output in the xhtml should it? i thought you only need this at the top of xml documents not xhtml webpages?
          Code:
          <?xml version="1.0" encoding="utf-8"?>

          Comment

          • jkmyoung
            Recognized Expert Top Contributor
            • Mar 2006
            • 2057

            #6
            Ok, just add the attribute omit-xml-declaration="no " to the xsl:output node.

            Comment

            • JoeS
              New Member
              • Jul 2007
              • 4

              #7
              That didn't work, but "omit-xml-declaration="ye s"" did :) Thanks ever so much for your help!

              Comment

              Working...