Trying CSS in XPP 9.3

Hi everyone:

I'm playing around with CSS in XPP 9.3. I am trying to recreate one of the examples in the book (See CSS.pdf, pages 4-14 - 4-15). The only thing I'm doing different is I'm trying to use the attr() function to pass along the value of the color attribute in my XML (<Para color="red">This is a para.</Para>).
My CSS has this line: Para[color]:before{ content: -xpp-perl(start_box, "attr(color)");}, and the perl function looks like this:
sub start_box {
$color = @_;
$X->set_text("Color is: $color");
$X->sfboxt("50", "$color");
}
I added the 'set_text' line to see what the value of the variable is, but it always comes back as 1, regardless of the color, so my boxed text is always grey. I've tried using a number instead of the color name, but get the same result. It seems to be returning the position of the attribute, and not the value. What am I doing wrong here?
Bart, I have your perl handout from the 2015 Conference, but it's a bit out of date now, since versions of XPP have changed a bit.
Thank you!!

Parents Reply
  • Tracey,

    I edited my answer to the correct syntax.
    It would be better and more correct to use the syntax '@color'.
    The difference between get_attr('@color') and get_attr('color') is that in the case of the @color you limit the search for the value of the color attribute to the current element.
    If you use just 'color' you are looking at the current element and if the attribute is not there you will try to find the value of the color attribute on any of the ancestors of the current element.
    (But since you have limited the CSS selector already to elements that do have the color attribute, my remark is purely theoretical.
    But it is good practice to start using '@color' in stead of just 'color' as in most of the case that is exactly what you mean.
Children