Generate proper META tag in HTML output?

Here should go questions about transforming XML with XSLT and FOP.
RBVanDyke
Posts: 35
Location: San Francisco, California USA

Generate proper META tag in HTML output?

Sat Aug 15, 2015 6:36 am

------
Oxygen 17, XSLT transform with Saxon6.5.5 transformer.

I'm using a book's examples to get started with XSLT.

One of the examples is generating HTML output without a closing META tag.
When I open the HTML output in oXygen 17, oXygen informs me, element "title" not allowed here; expected the element end-tag.
If I simply use the editor to add a </meta> tag to the HTML by hand, the error is remedied.

I want to please learn the correct way to eliminate this sort of error.

The Source XML

Code: Select all

<?xml version="1.0"?>

<message>You can use literal result elements in stylesheets.</message>

The XSL

Code: Select all

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>HTML Output</title>
      </head>
      <body>
        <p>
          <xsl:apply-templates/>
        </p>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

The HTML Output

Code: Select all

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <!-- NOTE that imply adding a </meta> closing here eliminates the error -->
   
      <title>HTML Output</title>
   </head>
   <body>
      <p>You can use literal result elements in stylesheets.</p>
   </body>
</html>>

I'm new to this so not sure what the correct way is to remedy this problem. I'm surprised that the process doesn't automatically add the </meta> tag if it's required(?)

Cheers & thanks for your help,
Riley
SFO
adrian
Posts: 2337

Re: Generate proper META tag in HTML output?

Mon Aug 17, 2015 5:02 pm

Hello,

Note that Oxygen doesn't validate HTML (SGML form), only XHTML (HTML in XML form).
Your meta tag is fine for HTML, so there is no problem there HTML-wise. It only needs to be closed for XHTML.

So the question is, what is the desired result, HTML or XHTML?

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
RBVanDyke
Posts: 35
Location: San Francisco, California USA

Re: Generate proper META tag in HTML output?

Mon Aug 17, 2015 6:10 pm

Adrian:

Thanks for the help.

So the question is, what is the desired result, HTML or XHTML?

I generally produce XHTML. So making an inferential leap, is the solution to modify the output method to say ="xhtml" ala?

Code: Select all

<xsl:output method="xhtml" indent="yes"/>

I'm just guessing -- really. As I said, I'm just getting started running XSLT.

Thanks 'gain,
Riley
SFO
adrian
Posts: 2337

Re: Generate proper META tag in HTML output?

Tue Aug 18, 2015 4:56 pm

Hi,

I'm afraid it's not that easy, because the XSL engine doesn't know about XHTML. You can see in the content completion list that for the method the possible values are 'xml', 'html' or 'text'. So, for XHTML you have to set the output method to 'xml':

Code: Select all

<xsl:output method="xml" indent="yes"/>

The side effect is that the meta tag will disappear from the output (it's no longer implied). So, if you still want it there, you'll have to manually add it in the stylesheet, inside the 'head' element:

Code: Select all

  <xsl:template match="/">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>HTML Output</title>
      </head>

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
RBVanDyke
Posts: 35
Location: San Francisco, California USA

Re: Generate proper META tag in HTML output?

Tue Aug 18, 2015 5:01 pm

Thank so much, Adrian, for your time and patience! Riley, SFO

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 1 guest