General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Different stylesheet for ‘Tags On’ and ‘Normal’ view?

  • rnv

    Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    Participants 7
    Replies 8
    Last Activity 10 years, 9 months ago

    Hi all,
    I am new to XMetal.
    is it possible to have different stylesheet for 'Tags On' and 'Normal' view?
    withb est regards,
    rnv

    Reply

    Derek Read

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    Yes, you can do this. It requires scripting.

    There is no example available that demonstrates this exactly. Your code would run inside the event On_View_Change and would have an if…then check for the current ViewType, which would then contain code to load a particular CSS.

    An example of switching the CSS manually (which could easily be adapted into an On_View_Change event macro) is included with the DocBook demo, which are the two items ending with “(DocBook)” in the Help > Samples menu. Once you have one of the samples opened you can select the menu item DocBook > Document Display > Use Stylesheet Example 1/2/3

    The customization for this demo lives here: AuthorRulesDocBook5.0xi

    Reply

    Derek Read

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    The DocBook example is pretty complex. It loads a JS file instead of putting all code directly in the MCR and does a few indirect things like using JScript prototypes, so it might be hard to decipher if you aren't familiar with those concepts.

    For that reason I've created the simplest possible example I can think of to make it easier to understand how to do this. All code is in the MCR file. See attached zip.

    The one thing my example doesn't do is write out the CSS to a file for use with Page Preview (Browser Preview). If you need that to continue to automatically generate XSLT for you (to transform to HTML for previewing) as it does when just a CSS file is being used you need to write out your CSS to disk (the control CSStoXSL.dll that generates XSLT needs to read from a file). Lots of customizers don't expect their users to use this feature, or they provide a hard-coded XSLT file so you might not need it. If you do, code that demonstrates how to do that is included with the previously mentioned DocBook demo, search for “deployPreviewCSS”.

    Reply

    rnv

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    Hi,
    thank you very much!! your simple example was really helpful.

    one more question:
    In the example the style of an element is specified in the macro code (example.mcr) itself.
    Is it possible to reference different css files for different views? e.g., example-tag.css, example-normal.css.
    with best regards,
    rnv

    Reply

    Derek Read

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    There is no setting or special filename that specifies a different CSS for a different view. The only two CSS files that are loaded automatically when a DTD is loaded are the ones that match .css and _structure.css

    There are other strategies for changing CSS using script but they do not work as well as this script example. Before we implemented the APIs I used in my example the only option was to have multiple files on disk, change the filename of one of them (to match the conventions above) and then use an older API to refresh the CSS.

    If you wish to load your CSS from a file (for authoring convenience for example) you could create separate CSS files (of any name) and load them into this script using the API Application.FileToString()

    Reply

    rnv

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    Thank you very much Derek! it works!

    I tried with Normal and TagsOn view. is it possible to modify Page (Browser) view as well with my own XSL stylesheet?

    once again really appreciate your help.

    regards,
    rnv

    Reply

    Derek Read

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    Yes you can modify the XSLT. If an XSLT file is not already present (first time you switch to Page Preview) one is auto-generated based on the currently loaded CSS file. However, once a file is present then it should be used and not generated again. So, provided you use the correct file name you can write your own. It is likely easiest to allow the file to auto-generate and then modify the generated file.

    When files are auto-generated they end up in your %appdata%SoftQuad folder. Look for XSLT files that have similar names to the CSS file associated with your schema here (which is typically the same as your schema file name):
    %appdata%SoftQuadXMetaL6.0Display_HTML.xsl
    %appdata%SoftQuadXMetaL6.0Display
    _HTML_Style.xsl

    If you wish to get a better understanding of what is happening with the Formatting Objects interface the scripts that make up the majority of that set of APIs are written in JavaScript and are in multipleOutput.mcr in the Startup subfolder. In addition, if you don't like where it places files you could modify its scripts. We can't really officially support that though, so be prepared to figure out exactly how it works and be careful (or leave it alone).

    Also, have a look at the documentation in the Programmers Guide for “Formatting Object interface” as it contains useful information. You can add functionality that lets the user generate HTML or PDF for both previewing or saving using this interface (previewing is basically the same as saving with the addition of either opening the file in Page Preview or an external viewer). The Journalist sample customization implements the following functions (that use the Formatting Object interface) on the Journalist toolbar: Save as HTML, View HTML, Save as PDF, View PDF. PDF uses Apache FOP. The Journalist sample remembers the last of the two functions you chose (View HTML and View PDF) so that in future you simply need to switch to Page Preview to see that format again.

    An alternative is to disable multipleOutput.mcr completely (by giving it a different file extension so it does not load or by removing it) and then referencing an XSLT style-sheet directly inside your XML document. In this case, when you switch to Page Preview, Internet Explorer will transform the document directly using the referenced XSLT file (the same as it will do if you open that file directly within an externally running copy of IE).

    Note: that none of the above applies to DITA documents. When working with DITA documents an entirely different process is used to generate documents for Page Preview that uses the DITA OT.

    Reply

    rnv

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    Thank you once again!! it works!!

    What does Page Preview does not support? does it support all tags supported by Internet explorer 7? looks like it does not support external css file.. am i right?

    regards,
    rnv

    Reply

    Derek Read

    Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?

    Page Preview actually is Internet Explorer embedded within XMetaL Author, so whatever you can do in your installed version of IE will be identical.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support