DITA and XMetaL Discussion

XMetaL Community Forum DITA and XMetaL Discussion Custom CSS and PI’s: little big problem

  • barbwire

    Custom CSS and PI’s: little big problem

    Participants 6
    Replies 7
    Last Activity 10 years ago

    Hi,

    I'm having strange situation, which requires some custom css. I have tried everything, but I'm not able to solve this issue. Maybe you guys can help me.

    I have topic (code cleaned):

    [code]



    Hi world!

     

    Hi!


    [/code]

    Now…. I have CSS-file (ditabase-base.css).

    This works OK:

    [code]
    [class~=”topic/topic”]>[class~=”topic/title”] /* H2 */ {
    display: block;
    font-weight: lighter;
    font-size: 140%;
    }

    [class~=”topic/topic”][something=”true”].[class~=”topic/topic”]>[class~=”topic/title”]{
    background-color: red;
    color: white;
    }[/code]

    It works fine. Title gets background-color red. But when the file has PI and the title background-color is supposed to be black, it ain't work anymore. This is my code, which doesn't work:

    [code]$PROCINS[xm-pi-target=”mypi”][xm-pi-data=”true”].[class~=”topic/topic”]>[class~=”topic/title”]{
    background-color: green;
    color: white;
    }[/code]

    It just doesn't work and I am amazed. Can somebody help me? What the hell I'm doing wrong? 🙂 I have tried all kind of combinations and nothing seems to work. Please, please, help me! 🙂

    Reply

    Derek Read

    Reply to: Custom CSS and PI’s: little big problem

    Periods inside a selector won't do anything in XMetaL so we should start by removing those just to make things clear and not introduce any other issues. The W3C discusses this type of selector in the context of HTML only and XMetaL doesn't recognize them. I'm actually a little surprised that it seems to be ignoring them but still making sense of the rest of the selector. The equivalent to using a period is supported in XMetaL though and that is [attr~="value"] which you are using here.

    What I suspect is happening with your PI selector is that the support we added for styling PIs was meant to be used just for that; to style the PI itself. I don't think any testing has been done to include a PI in a selector where the styling affects something else. For this reason it is very possible that what you are trying to do is currently unsupported. Not actually that surprising if you consider that the ability to style PIs is a CSS extension that we invented for XMetaL's rendering engine (at the request of a few clients a few years ago).

    I'll need to confirm that though. The developer that does most of the coding for the formatting engine would be the best person to ask. He's on vacation at the moment.

    Reply

    Derek Read

    Reply to: Custom CSS and PI’s: little big problem

    My assumption was correct. The type of selector you want to build that includes a PI isn't supported. You will need to find another way to uniquely identify the element in question.

    If you can't build an alternate selector (possibly requiring you to add more markup to the XML) you might wish to look at styling the element using the Range.ContainerStyle API inside a script. Your script would need to find the element.

    Reply

    barbwire

    Reply to: Custom CSS and PI’s: little big problem

    My assumption was correct. The type of selector you want to build that includes a PI isn't supported. You will need to find another way to uniquely identify the element in question.

    If you can't build an alternate selector (possibly requiring you to add more markup to the XML) you might wish to look at styling the element using the Range.ContainerStyle API inside a script. Your script would need to find the element.

    Damn. Thanks anyway. Have to use different attribute on the root element or I just have to make DTD specialization for this problem.

    Well, maybe in next XMetal version this works… 😉

    Reply

    Derek Read

    Reply to: Custom CSS and PI’s: little big problem

    I'd really consider using Selection/Range.ContainerStyle() unless you really don't want to do any scripting.

    Reply

    Derek Read

    Reply to: Custom CSS and PI’s: little big problem

    Here's a script example of something that might get you close to what you need:

    [code]//XMetaL Script Language JScript:
    var rng = ActiveDocument.Range;
    var nodes = ActiveDocument.getNodesByXpath(“//topic/processing-instruction('mypi')/../title”);
    for(i=0;i rng.SelectNodeContents(nodes(i));
    rng.ContainerStyle=”background-color:green; color:white;”;
    }[/code]

    Reply

    barbwire

    Reply to: Custom CSS and PI’s: little big problem

    Here's a script example of something that might get you close to what you need:

    [code]//XMetaL Script Language JScript:
    var rng = ActiveDocument.Range;
    var nodes = ActiveDocument.getNodesByXpath(“//topic/processing-instruction('mypi')/../title”);
    for(i=0;i rng.SelectNodeContents(nodes(i));
    rng.ContainerStyle=”background-color:green; color:white;”;
    }[/code]

    Thank you. Have to try this as soon as possible.

    Reply

    barbwire

    Reply to: Custom CSS and PI’s: little big problem

    Well I tried and it indeed worked!

    Big thanks to you Derek! I owe you a beer or something! 🙂

    I did not use CSS at all. I did the customization to the *.mcr file. Tested with in several test cases and it worked.

    [code]var pathpi = ActiveDocument.getNodesByXPath(“//topic/processing-instruction('my-pi')”);
      var pathtitle = ActiveDocument.getNodesByXPath(“//topic/title”);
      var rng = ActiveDocument.Range;
      var pathattr = ActiveDocument.getNodesByXPath(“//topic/@something”);
      if(pathpi.length > 0){
        var docpathpi = pathpi.item(0);
      var docPath = docpathpi.nodeValue;    
      if(docPath == “true”){
    rng.SelectNodeContents(pathtitle(0));
    rng.ContainerStyle=”background-color:transparent; color:black;”;
      }
      else if(docPath == “false”){
    if(pathattr.length > 0){
    var attrvalue = pathattr.item(0).nodeValue;
    if(attrvalue == “true”){
    rng.SelectNodeContents(pathtitle(0));
    rng.ContainerStyle=”background-color:red; color:white;”;
    }
    }
      }
      }
      else if(pathtitle.length > 0){
    if(pathattr.length > 0){
    var attrvalue = pathattr.item(0).nodeValue;
    if(attrvalue == “true”){
    rng.SelectNodeContents(pathtitle(0));
    rng.ContainerStyle=”background-color:red; color:white;”;
    }
    }
      }[/code]

    Reply

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

Lost Your Password?

Products
Downloads
Support