Outputting text content before HTML node in DITA/XHTML transformation
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 20
- Joined: Fri Feb 20, 2015 10:25 am
Outputting text content before HTML node in DITA/XHTML transformation
Hi there,
I'm trying to output content before the root HTML node in a DITA -> XHTML transformation. I located the XSLT section from dita2htmlImpl.xsl, where the <html> element is generated, but entering any text content before it produces the following error:
This is a model of the XSLT I was using:
Do you know of any way to accomplish what I'm trying (ie. entering text and XSL variables before the root node of the HTML document)?
I'm trying to output content before the root HTML node in a DITA -> XHTML transformation. I located the XSLT section from dita2htmlImpl.xsl, where the <html> element is generated, but entering any text content before it produces the following error:
Code: Select all
System ID: /Applications/oxygen/frameworks/dita/DITA-OT2.x/plugins/org.mycashflow.xhtml.docs/faq-question.dita
Scenario: DITA XHTML MCF
Input file: /Applications/oxygen/frameworks/dita/DITA-OT2.x/plugins/org.mycashflow.xhtml.docs/faq-question.dita
Engine name: DITA-OT
Severity: fatal
Description: When 'standalone' or 'doctype-system' is specified, the document must be well-formed; but this document contains a top-level text node
Start location: 40:0
Code: Select all
<!-- Matches /dita or a root topic -->
<xsl:template match="*" mode="root_element" name="root_element">
<xsl:call-template name="chapter-setup"/>
</xsl:template>
<xsl:template name="chapter-setup">
<!-- This causes problems. -->
<xsl:variable name="metafield">
<xsl:value-of select="topic/element/@attribute"/>
</xsl:variable>
TEXT and {$metafield}
<html>
<xsl:call-template name="setTopicLanguage"/>
<xsl:value-of select="$newline"/>
<xsl:call-template name="chapterHead"/>
<xsl:call-template name="chapterBody"/>
</html>
</xsl:template>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Outputting text content before HTML node in DITA/XHTML transformation
Hi,
What is the desired result? Why do you want to output text before the html root node?
Note that the output is not HTML, but XHTML which must be XML well formed, so this is not possible without changing the output type. You should be able to output there XML comments or processing instructions which do not break the XML well-formedness, but definitely not text.
e.g.
Regards,
Adrian
What is the desired result? Why do you want to output text before the html root node?
Note that the output is not HTML, but XHTML which must be XML well formed, so this is not possible without changing the output type. You should be able to output there XML comments or processing instructions which do not break the XML well-formedness, but definitely not text.
e.g.
Code: Select all
<xsl:comment>TEXT and <xsl:value-of select="$metafield"/></xsl:comment>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 20
- Joined: Fri Feb 20, 2015 10:25 am
Re: Outputting text content before HTML node in DITA/XHTML transformation
Thanks for the reply. We are experimenting with publishing DITA through Jekyll, which uses YAML variables that are placed before any other content in the HTML file. We would like to fetch metadata from DITA during the transformation to HTML and enter it into the YAML front matter.
I changed the transtype to "html5", which did output the content, but in the wrong place. This was the result:
I don't know what happened, but obviously that won't work.
I then used <xsl:output method="html"></xsl:output> in my XSLT and did this:
This managed to get the content between <html> and the Doctype declaration, which is still the wrong place, on top of which the content is in an HTML comment, which doesn't work (although I'm sure there's a workaround for this).
I changed the transtype to "html5", which did output the content, but in the wrong place. This was the result:
Code: Select all
<html xmlns:dita2html="http://dita-ot.sourceforge.net/ns/200801/dita2html" lang="en-us">
<head></head>
<body id="question-id">TEXT and {$metafield}
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2017">
<meta name="DC.rights.owner" content="(C) Copyright 2017">
<meta name="DC.Type" content="faq-question">
<meta name="description" content="Blaa"><meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="question-id">
<link rel="stylesheet" type="text/css" href="commonltr.css">
<title>Can I add attributes to specific element types?</title>
I then used <xsl:output method="html"></xsl:output> in my XSLT and did this:
Code: Select all
<xsl:template name="chapter-setup">
<xsl:comment>TEXT and <xsl:value-of select="topic/element/@attribute"/></xsl:comment>
<html>
<xsl:call-template name="setTopicLanguage"/>
<xsl:value-of select="$newline"/>
<xsl:call-template name="chapterHead"/>
<xsl:call-template name="chapterBody"/>
</html>
</xsl:template>
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Outputting text content before HTML node in DITA/XHTML transformation
Hi,
So you have a DITA OT plugin customization which adds an HTML XSLT stylesheet customization, right?
And you set the xsl:output something like this in the custom stylesheet:
This should override the default xsl:output declaration. I'm not sure why you still get the DOCTYPE in the HTML output though.
You can probably use such a construct:
to output some tags before the root element.
If all else fails you can post-process the result HTML documents using regular expressions.
You can write your own ANT build file which invokes the DITA OT processing and afterwards may alter the resulting HTML documents:
https://www.oxygenxml.com/doc/versions/ ... -file.html
Regards,
Radu
So you have a DITA OT plugin customization which adds an HTML XSLT stylesheet customization, right?
And you set the xsl:output something like this in the custom stylesheet:
Code: Select all
<xsl:output method="html"/>
You can probably use such a construct:
Code: Select all
<xsl:text disable-output-escaping="yes"><![CDATA[<abla></abla>]]></xsl:text>
If all else fails you can post-process the result HTML documents using regular expressions.
You can write your own ANT build file which invokes the DITA OT processing and afterwards may alter the resulting HTML documents:
https://www.oxygenxml.com/doc/versions/ ... -file.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service