CSS select previous sibling

Questions about XML that are not covered by the other forums should go here.
dvezina
Posts: 23
Joined: Sat Mar 08, 2014 12:10 am

CSS select previous sibling

Post by dvezina »

Hi,

My CSS looks like this:

Code: Select all


CITY + NEIGHBORHOOD[name=""] {
display:inline;
font-style:italic;
content: oxy_xpath("//CITY/@name");
}
My XML looks like this:

Code: Select all


<LISTING>
<COUNTRY geo_id="0" id="1051" name="Canada"/>
<STATE geo_id="0" id="48999" name="North America|Canada|British Columbia"/>
<CITY geo_id="0" id="5503" name="North America|Canada|British Columbia|Whistler"></CITY>
<NEIGHBORHOOD geo_id="" id="0" name=""/>
</LISTING>
The expected output is:
North America|Canada|British Columbia|Whistler

Does anyone see why this doesn't work.

THANKS
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: CSS select previous sibling

Post by alex_jitianu »

Hi,

I tested the samples you provided and in my case the author mode presented just what you've expected : North America|Canada|British Columbia|Whistler. Perhaps there is a StylesFilter involved and it also changes the styles of the element? If not, what Oxygen version you are using? If you test these samples in a fresh Oxygen installation (one that has just the default frameworks) are they working as expected?

Best regards,
Alex
dvezina
Posts: 23
Joined: Sat Mar 08, 2014 12:10 am

Re: CSS select previous sibling

Post by dvezina »

There is a StyleFilter and DocumentModificationFilter (setAttribute) in play.

If CITY and NEIGBORHOOD are in LISTING, they are form controls. If they are a chapter, I render them as normal text. Everything seems to work but the xpath with the attribte that doesnt work.

My StyleFilter code is:

Code: Select all


		else if (authorNode.getName().equals("CITY")) {
// getOwnerDocument returns null when part of DocumentFrgement
// This is what crashes [+ City] action
AuthorNode authorDocument = authorNode.getOwnerDocument();
if (authorDocument != null) {
AuthorElement rootElement = authorNode.getOwnerDocument().getRootElement();
if (rootElement.getName().equals("LISTING")) {
EditorContent editorContent = geosBuilder.getEditorContent("city");
styles.setProperty(Styles.KEY_MIXED_CONTENT, new StaticContent[] {editorContent});
returnAlteredStyles = true;
}
}
}
else if (authorNode.getName().equals("NEIGHBORHOOD")) {
// getOwnerDocument returns null when part of DocumentFrgement
// This is what crashes [+ Hood] action
AuthorNode authorDocument = authorNode.getOwnerDocument();
if (authorDocument != null) {
AuthorElement rootElement = authorNode.getOwnerDocument().getRootElement();
if (rootElement.getName().equals("LISTING")) {
EditorContent editorContent = geosBuilder.getEditorContent("hood");
styles.setProperty(Styles.KEY_MIXED_CONTENT, new StaticContent[] {editorContent});
returnAlteredStyles = true;
}
}
}
My CSS is attempting th following: (1) If NEIGHBORBHOOD/@name is empty or does not exist, print CITY/@name, (2)Otherwise print NEIGHBORHOOD/@name.

Code: Select all


/*DOES NOT WORK/
CITY + NEIGHBORHOOD[name=""] {
display:inline;
font-style:italic;
content: ", " oxy_xpath("//CITY/@name");
}

/*WORKS*/
CITY + NEIGHBORHOOD[name*="|"] {
display:inline;
font-style:italic;
content: ", " oxy_substring(attr(name), oxy_add(oxy_lastindexof(attr(name), '|'), 1, integer));
}

/*WORKS*/
CITY + NEIGHBORHOOD[name] {
display:inline;
font-style:italic;
content: ", " oxy_substring(attr(name), oxy_add(oxy_lastindexof(attr(name), '|'), 1, integer));
}
What I did notice is that if I use oxy_xpath("//CITY/text()"), I do get the text. So it appears to be the name attribute. I will try to run this down in the DocumentModificationsFilter.

Thanks for your help
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: CSS select previous sibling

Post by alex_jitianu »

Hi Deanna,

The code below, changes the content property in the styles. This is the same property on which you put the oxy_xpath() on. The StylesFilter is applied last so it will override the rule from the CSS.

Code: Select all


else if (authorNode.getName().equals("NEIGHBORHOOD")) {
// getOwnerDocument returns null when part of DocumentFrgement
// This is what crashes [+ Hood] action
AuthorNode authorDocument = authorNode.getOwnerDocument();
if (authorDocument != null) {
AuthorElement rootElement = authorNode.getOwnerDocument().getRootElement();
if (rootElement.getName().equals("LISTING")) {
EditorContent editorContent = geosBuilder.getEditorContent("hood");
styles.setProperty(Styles.KEY_MIXED_CONTENT, new StaticContent[] {editorContent});
returnAlteredStyles = true;
}
}
}
You should probably add some checks in the StylesFilter to only change the content property of NEIGHBORBHOOD so that it doesn't overlap with the CSS rules. It's strange that oxy_xpath("//CITY/text()") works, because from the StylesFilter code looks like it always overrides the content of NEIGHBORBHOOD.

Best regards,
Alex
Post Reply