General XMetaL Discussion
rnv January 2, 2012 at 3:19 pm
Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 2, 2012 at 3:19 pmParticipants 7Replies 8Last Activity 11 years, 1 month ago
I am new to XMetal.
is it possible to have different stylesheet for 'Tags On' and 'Normal' view?
withb est regards,
rnvDerek Read January 3, 2012 at 6:18 pm
Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 3, 2012 at 6:18 pm
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.0xiDerek Read January 3, 2012 at 7:55 pm
Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 3, 2012 at 7:55 pm
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”.rnv January 6, 2012 at 12:40 pm
Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 6, 2012 at 12:40 pm
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,
rnvDerek Read January 6, 2012 at 5:43 pm
Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 6, 2012 at 5:43 pm
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
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()rnv January 9, 2012 at 1:23 pm
Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 9, 2012 at 1:23 pm
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.
rnvDerek Read January 9, 2012 at 6:53 pm
Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 9, 2012 at 6:53 pm
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):
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.rnv January 11, 2012 at 11:21 am
Reply to: Different stylesheet for ‘Tags On’ and ‘Normal’ view?January 11, 2012 at 11:21 am
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?
- You must be logged in to reply to this topic.