DITA and XMetaL Discussion

  • sandvik

    CSS challenge

    Participants 6
    Replies 7
    Last Activity 11 years, 9 months ago

    [I'm looking for a solution to this for XMAX 5.5, but I think it applies to DITA solutions as a
    whole. So I'm posting to the DITA forum.]

    We'd like to add a CSS rule to flag “extra” titles in section or example elements. Per the language spec, a section or example should have at most one title, but the DTD does not enforce the restriction. We'd like to flag titles after the first occurrence in the editor.

    I'm having trouble getting this work in XMAX 5.5. The following bare bones rule is not working:
    section>title~title:before {
        content: “[Misplaced title] “;
        color:red;
        font-weight: bold;
    }

    Does XMetaL (and XMAX 5.5) support the ~ general sibling constructor? Is there another way to do this?

    thanks,
    – Craig

    Reply

    Derek Read

    Reply to: CSS challenge

    The products (up to and including version 6.0) do not support ~ however they do support +

    So you can do this:

    section > title + title:before {
    }

    That isn't going to give you exactly what you want though obviously because this means the titles must be adjacent.

    You might create a series of selectors like this though:
    section > title + title:before {
    }
    section > title + * + title:before {
    }
    section > title + * + * + title:before {
    }
    section > title + * + * + * + title:before {
    }

    But then you need to guess how many elements an author might put in there between title. Not the best solution I guess, unless you do already have some other strict editing guidelines that people follow.

    I think in order to try to really guide your authors you have at least two options:

    1) Change the DTD, or in the case of DITA specialize the DTD. In this case the standard validation rules will be enforced according to what you set up and everything else in the product will “just work”.

    2) Create a script that walks the document and displays a message when these other titles are found, and maybe takes the author to the first instance and maybe even offers to delete it or all “bad” occurrences. Or the script might set CSS on these specific elements using Selection.ContainerStyle to highlight these “bad” titles in a different colour or perhaps outlines them with a border, or both.

    If I can find the time, I could try to throw a script together for you. If you have any further specifics (beyond the generality that this is for XMAX 5.5) that would help. It sounds like you are in fact using the DITA DTDs with your XMAX customization.

    Reply

    sandvik

    Reply to: CSS challenge

    Thanks for the quick reply. Unfortunately it's not practical for us to change the DTD.

    A script that runs during validation might do the trick, but I don't know if a validation event macro in XMAX can tell the container that the document is invalid. The 5.5 Programmer's Guide indicates that the Application.ValidationSuccess property works for Author only.

    You guys should probably consider some kind of add on validation for this scenario in the DITA editions of Author.

    thanks,
    – Craig

    Reply

    Su-Laine Yeo

    Reply to: CSS challenge

    I think I have a solution. This one uses two statements:

    section>title:before {
        content: “[Misplaced title] “;
        color:red;
        font-weight: bold;
    }

    section>title:first-child:before
    {
    content: “”;
    color: Black;
    }

    Reply

    sandvik

    Reply to: CSS challenge

    Su-Laine,
    That looks really close, but that CSS would flag that was preceded by <indexterm>, and I don't think the markup is out-of-whack in this case. </p> <p>– Craig</indexterm>

    Reply

    Derek Read

    Reply to: CSS challenge

    This script will highlight all the “unwanted” titles (matching your description of unwanted):

    [code]//XMetaL Script Language JScript:
    var rng = ActiveDocument.Range;
    var unwantedTitles = ActiveDocument.getNodesByXPath(“//section/title[position() > 1]”);
    for (i=0;i rng.SelectNodeContents(unwantedTitles(i));
    rng.ContainerStyle = “background-color:yellow; color:red”;
    }[/code]

    There are various events this can be called from but as you are writing an XMAX application you have control over when the user can save and when they can validate, so you could add this code before or after any other code you have written that runs when the user indicates (using your UI) that they want to perform either of these actions. Ultimately you are making the call to the XMAX Save() method.

    Again, since this is XMAX which does not provide a “Validation Log” (as Author does) you will have built something analogous (if you are displaying validation errors to the end user). You could add additional errors into whatever you are displaying to the user, perhaps like the following:
    “Corporate standards do not allow sections to contain titles anywhere except as the first element. Please remove all highlighted titles.”

    Or you might throw up a different “Business Rules Violation” dialog that contains these types of errors (for users that question why this is valid DITA, but still not allowed). That would distinguish it from your “standard” list that gets its list of validation errors from the ValidationErrorList API.

    So, your logic for your save action would perform this check (using a similar script to the one above) and if it fails (ie: the node count is > 0) you would just not call the Save() method (and then optionally tell the user why).

    You might prompt the user with something like this:
    “Corporate standards do not allow

    elements to contain a anywhere except as the first child element. Would you like to remove unwanted elements? [Yes / No]”</p> <p>Then if they answer “Yes” you would have a similar script to the one above that would move to each unwanted title element and remove it from the document. In this case Save() could then be called as the document would then meet your standards.</p> <p>If the user answers “No” you might highlight them all so it is clear which are unwanted. In this case the user might move the text they contain somewhere else, or use it as a reference to rewrite a paragraph or something before doing the deletions.</p> <p>Or maybe you just tell the user the document is going to be “fixed” and you don't even give them a choice, then remove the elements automatically and call <tt>Save()</tt>.

    Reply

    Derek Read

    Reply to: CSS challenge

    One thing I didn't mention here is that you cannot access (or create) the pseudo elements :before or :after using ContainerStyle, which is why my script is merely highlighting the unwanted title elements using background-color and color. However, you could put a border around them as well (or instead), or change them to italic, underline, font-size, font-family, etc.

    There is a way to change the rendered content for any given element so you could display “[Misplaced title] ” for each one. Let me know if what I have written doesn't cut it and I'll look into that. Or you could have a look at the API called SetRenderedContent() yourself.

    Reply

    Su-Laine Yeo

    Reply to: CSS challenge

    Another CSS option: OK, this is hacky, but it should work for one or two elements preceding the first title, and you can extend it to account for as many elements as you're likely to have.

    /*Assume section titles are misplaced*/
    section>title:before {
        content: “[Misplaced title] “;
        color:red;
        font-weight: bold;
    }

    /*Title which is the first element in a section*/
    section>title:first-child:before
    {
    content: “”;
    color: Black;
    }
    /*Title which is the second element in a section, after an indexterm*/

    section>indexterm:first-child + title:before
    {
    content: “”;
    color: Black;
    }

    /*Title which is the second element in a section, after two indexterms*/

    section>indexterm:first-child + indexterm + title:before
    {
    content: “”;
    color: Black;
    }

    Reply

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

Lost Your Password?

Products
Downloads
Support