Can XSLT be used to apply CSS styles? - xslt

I have some XML and a very small XSLT to convert that into HTML. When I import my XML content in InDesign using the XSLT, I can see the styles are applied to the elements on the left hand browsing side but, when I drag and drop the elements in the InDesign frames, nothing is happening. The content is flowing normally.
My question is, in InDesign, is XSLT getting used only for sequencing the elements or can we use XSLT to apply the styles (like font-size, line-spacing etc.) as well for elements?
Also, if you can send me any sample XSLT for converting an XML to HTML tags or any example, that will be great.

In general, formatting in InDesign has nothing in common with CSS styles -- that is a HTML construction, not an XML one. You can indeed only reorder elements (and other element-wise stuff, such as removing, replacing, or adding tags).
Formatting can be applied to the tags after you imported/translated your XML using Map Styles To Tags (or Map Tags to Styles; I don't think I've ever used either).

You can use HTML within XLST so, if you have something like:
<xsl:value-of select="node"/>
Then this can also be written like:
<div class='style'><xsl:value-of select="node"/></div>
Or you can use inline CSS like:
<div style='color:red;'><xsl:value-of select="node"/></div>
Hope this helps!

Related

Hide a topic from PDF output at xsl level

I have a topic, which only contains some metadata (childs of prolog and some custom elements too) of the documentation. The contents of these elements is displayed in headers and footers in the acutal PDF output.
My problem: now the referred topic itself included in the pdf as an empty chapter.
Setting the processing-role to resource-only or filtering the topic does not solve the problem, as the content of the elements is needed in the further steps of the transformation (headers, footerst ect..)
My best guess is to somehow exclude this one topic and the needless page sequence based on its ID with..
.. adding some attributes in a custom xsl template?
.. modification of topic processing?
.. an obvious method that didn’t occur to me?
but I’m a beginner, so a little guidance would be nice.
Currently using:
DITA-OT 2.1; Oxygen 17.1; Bookmap spec.; XSL FO based transformations;
Thanks in advance!
Maybe instead of keeping that content inside the topic, you could keep it inside the main DITA Map, maybe using some DITA "data" elements like:
<map>
<title></title>
<topicmeta>
<data name="d1" value="v1"/>
</topicmeta>
Anyway if you plan to continue with having a separate topic, maybe you can set on that topic an "outputclass='filtered'" attribute and then use Oxygen's Find/Replace in Files to search in the folder "DITA-OT/plugins/org.dita.pdf2" for "bookmap/chapter". You probably need to find the XSLT templates which process DITA "chapter" elements for the table of contents, bookmarks area and for the main document and add a [not(#outputclass='hidden')] condition to them so that they skip that topic.

Eliminate javascript from HTML with XSLT

I am trying to transform an HTML report into XML, but some javascript in the file is throwing errors, due to statements with a less-than character (e.g., for(var i=0; i<els.length;i++) ). I thought I could eliminate the javascript with the following template, which should remove entire script nodes:
<xsl:template match="script"/>
I assumed the XSLT processor would simply skip over the entire script nodes, but it's still throwing the same errors. I also tried adding this one:
<xsl:template match="script/text()"/>
No luck. If I manually remove all the javascript from the file, my transform works, but that's not practical as I need to create and run a daily automated process on these HTML files to extract some data in the HTML tables.
As a general rule, XSLT will only process well-formed XML input: it's not designed to process other formats like HTML.
However, XSLT will generally accept input from a parser that delivers a stream of events that looks sufficiently like an XML stream. This allows parsers like TagSoup and validator.nu to be used as a front-end to your XSLT processor.
Saxon packages this up with a parse-html() function that invokes TagSoup to parse HTML input and turn it into a DOM-like tree (actually an XDM tree) that it can process as if it came from XML.
validator.nu is a more up-to-date HTML parser than TagSoup, but you would have to do a little more work to integrate that.
Question was answered by Martin Honnen in the comments:
oxygenxml.com/doc/versions/18.1/ug-editor/tasks/… suggests there is an HTML import feature so try whether that helps. Of course there are standalone applications like HTML Tidy I think you can use outside of the XSLT processsing to first convert your HTML to XHTML.

I want to try a tag not closed with xpath

I want to try a tag not closed with xpath like this:
<figure class="img"><img class="immagine-in-linea-senza-cornice" width="16%" src="images/schema_1_fmt.jpeg" alt=""/>
I want to close the tag with a xslt transformation.
XPath does not work directly on the input document, but on an abstract, tree-like representation of the document (e.g. XDM or DOM). In this model, opening and closing tags of an element are not represented at all. Instead, an element appears as a single entity in the tree.
Therefore, manipulating < and /> is completely out of the question for languages like XPath, because the concept of opening and closing tags is simply not implemented. I would argue that this abstraction is an advantage of the models, though.
Also, XSLT transformations normally take as input XML documents. If your document has unclosed elements, it will be rejected by any application that is only prepared to process XML.
In short, fix the XML document with a language other than the combination of XSLT and XPath (see e.g. here), and think about XSLT as soon as you have well-formed XML as input.

What does <var name="ROMAN"> mean in xsl

I am really facing a strange problem. ROMAN characters are not displaying at all in mozilla and google chrome except on IE8(not in IE10 as well).
The code was written using xsl transformations. and i am unable to find what does
<var name="ROMAN"> is? This is the exact text when i see the html source.
Even the same code is written in xsl.
Any help would be greatly appreciable.
<var> is an HTML element that means "This is a variable". It will typically cause the contained text to be rendered in italic. It doesn't mean anything special to XSLT, it's just like any other HTML element name. name="ROMAN" is just like the name attribute of any other HTML element, it can be used in Javascript to address the relevant element node in the page. It doesn't change the rendition of the element, unless perhaps there is some stylesheet somewhere that recognizes name="ROMAN" and associates it with a display style.
I think you've got an HTML question, not an XSLT question. There's something wrong with your HTML, and we don't know what, because you haven't given enough information.

XSLT - how to deal with <![CDATA[

Im trying to output some XML using XSLT, however I've just come across this:
<description><![CDATA[<p>Using Money – recognise coins, getting change, paper money etc. A PowerPoint resource containing colour coded levels to suit different abilities – special needs. Self checking and interactive.</p>]]></description>
How do I output the actual HTML, not the <P>, but as if it was HTML?
You can use disable-output-escaping. Beware, though, that if the input value is not well-formed or valid, the output won't be either.
<xsl:value-of select="description" disable-output-escaping="yes"/>
XSLT handles data already parsed by the XML parser. The CDATA tags are parsed as text by the XML parser. You might need to do some pre-processing to remove the CDATA tags before turning over the XML to XSLT.