aspose file tools*
The moose likes XML and Related Technologies and the fly likes XSLT: set attribute for all ancestors based on child Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT: set attribute for all ancestors based on child" Watch "XSLT: set attribute for all ancestors based on child" New topic
Author

XSLT: set attribute for all ancestors based on child

Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
I am using XSLT to transform an XML document to HTML. I would like to have an attribute "wripple up" a hierarchy. The easiest way to explain this is an example (the real case is super complex, so I'm using an example that captures the essence of my problem).
I'm laying out this email list as a "tree" of ULs. The emails can have an attribute "unread" which can be set to "T". If unread is T, I want the email and all its ancestors to be displayed in bold:

Here is the XSLT I use:

As you can see, this XSLT only sets the lowest level (email) to bold. What I want is for the Sender of that email to have its style attribute set the same way as the unread email's (that is, a Sender is bold if one or more of its children is bold)
In real life, this hierarchy will be deeper, but the number of levels is always constant.
Does anyone know how to make the parent levels "inherit" this attribute from their children? Thanks in advance.
--
Tim Allen
Especialista General
[ October 02, 2003: Message edited by: Tim Allen ]

Timothy Chen Allen
Learn Spanish in Washington, DC
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
replace

with


The test checks if you have any nodes of email that has 'T' as attribute.


Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
Dear Tony,
That works great! I see that I tried to solve the problem from the wrong direction. I did not realize that I could reference the children of a node in the test.
Thanks again.
Timothy Chen Allen
Ranch Hand

Joined: Mar 16, 2003
Posts: 161
A little update:
I was able to implement this solution in a much deeper hierarchy by placing code like this in the template for each hierarchy level:

Tony, you are the man.
[ October 03, 2003: Message edited by: Tim Allen ]
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSLT: set attribute for all ancestors based on child