Forgot password? | Forgot username? | Register

How can Page Views be conditionally formatted?

How can Page Views be conditionally formatted?

Hi there,
I'm trying to make a page view that changes color depending on values in certain fields--e.g., the department attached to an event record.  (For example, show a red background or red somewhere for event records when the "SecDepartment_tab" field is "Zoology;" show green if that field is "Botany," etc.)

So far, by using an "xsl: when" test in the "data template" section of the standard page view xslt stylesheet, we've managed to set rows to show [scary] colors, but no luck getting the color to change based on the fields/values we're trying to specify...I've been trying different ways of specifying the field, and trying other sections of the stylesheet in case the "data template" isn't the place for this.

In the meantime, though, does anyone out there have wisdom to share on conditionally formatting page views?

If it helps, a chunk of our xsl is below (possibly messy, but I'm happy to send a clearer copy of the actual xsl file we're attaching to the page view if anyone wants a look.)
Thanks for any help!
-Kate

---------------------beginning of our xsl chunk---------------------
    <!--
            Data template
     -->
    <xsl:template name="data">
           <xsl:variable name="column" select="document('')/*/emu:column[@name=current()/@name]" />
      <xsl:choose>
        <xsl:when test="not(atom[@name='EveTypeOfEvent'] = 'Video')">
<tr class="values">
            <td class="values" bgcolor="#00ffff">
                <table border="0" class="data" id="datatable">
                    <xsl:apply-templates select="*" />
                </table>
            </td>
        </tr>
        </xsl:when>
        <xsl:when test="not(atom[@name='EveTypeOfEvent'] = 'Exhibit - Temporary')">
        </xsl:when>
        <xsl:when test="not(atom[@name='EveTypeOfEvent'] = 'Technology')">
        </xsl:when>
        <xsl:otherwise>
<tr class="values">
            <td class="values" bgcolor="#ff33ff">
                <table border="0" class="data" id="datatable">
                    <xsl:apply-templates select="*" />
                </table>
            </td>
        </tr>
            </xsl:otherwise>
      </xsl:choose>
      <!--
<tr class="values">
            <td class="values">
                <table border="0" class="data" id="datatable">
                    <xsl:apply-templates select="*" />
                </table>
            </td>
        </tr>
        -->
    </xsl:template>

---------------------end of xsl chunk---------------------

Kate Webbink
Information Systems Specialist
useravatar
Offline
10 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How can Page Views be conditionally formatted?

Hi Kate

I think the thing to do is associate the color with some new classes in the CSS which are named after your collections. Then use the xsl to create a DIV with the class that matches the colour you want.

The forum wouldn't accept multiple xml code blocks to explain and demonstrate this so I've attached a text file below with contains a much longer and more detailed explanation.

Please do let me know if any of the explanation doesn't make sense, or if it does make sense but doesn't work as expected

Regards
Keith

(South Australian Museum)
conditional-page-colours.txt

Edited by: Keith Maguire - 07-Mar-14 14:11:30

Keith Maguire
South Australian Museum
useravatar
Offline
11 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How can Page Views be conditionally formatted?

Hi Keith,
Many thanks for the wisdom! (and for braving the eye-searing colors!)
The explanation makes sense, but I haven't been able to get it to work yet.  I think our department field "SecDepartment_tab" is a table (or at least not an atom), so I'm not sure how the syntax needs to change in order to reference it.  (Just changing the name of the ref from your example didn't work.) 

If interested, we've almost gotten something else to work:  Instead of just adding a css class for each condition (which is probably cleaner & more specific), we used a "when" test in the Atom template to color code for Event Type (we have "Video," "Exhibit - Temporary," etc). 

Downsides are that the code is messier, and if any other field values ever happen to match the Event Type's value, they'd probably get color-coded, too.  (I also couldn't get this method to work for our departments.)

...So I'll keep trying to work out the css-approach you recommended...If you have further advice, I am all ears.  Again, thank you!
-kate

What we currently have is attached (in full) and pasted below (in part)
color-event-type.txt
color-coded-dpt.txt
...each attached .txt is an .xsl, without the header:  <?xml version="1.0" encoding="ISO-8859-1" ?>


   <!--
            Atom template
     -->
    <xsl:template match="atom">
        <xsl:variable name="column" select="document('')/*/emu:column[@name=current()/@name]" />
    <xsl:choose>
        <xsl:when test=".= 'Botany'">
           <tr class="atomvalue">
                <td class="atomprompt">
                    <xsl:call-template name="prompt">
                        <xsl:with-param name="column" select="$column" />
                    </xsl:call-template>
                </td>
                <td class="atomvalue" bgcolor="#b2D487">
                  <xsl:value-of select="." />
                </td>
            </tr>
        </xsl:when>
        <xsl:when test=".='Zoology'">
          <tr class="atomvalue">
                <td class="atomprompt">
                    <xsl:call-template name="prompt">
                        <xsl:with-param name="column" select="$column" />
                    </xsl:call-template>
                </td>
                <td class="atomvalue" bgcolor="#d04123">
                  <xsl:value-of select="." />
                </td>
            </tr>
</xsl:when>
        <xsl:otherwise>
          <tr class="atomvalue">
                <td class="atomprompt">
                    <xsl:call-template name="prompt">
                        <xsl:with-param name="column" select="$column" />
                    </xsl:call-template>
                </td>
                <td class="atomvalue">
                    <xsl:value-of select="." />
                </td>
            </tr>
    </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

Kate Webbink
Information Systems Specialist
useravatar
Offline
10 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How can Page Views be conditionally formatted?

Hi Kate


Hmm... our SecDepartment_tab is a table too, which then contains a tuple which contains an atom called SecDepartment. So in theory it should work... Maybe I forgot to include something in the original typing out of the answer.

Would you be able to attach a copy of the xml produced for the page view? Using that I (hopefully) should be able to get it working for you

Assuming you're using Windows, run the page view XSL report as a report for a single entry. You can find the xml for the report in the folder
C:\Users\YOUR_LOGIN_NAME\AppData\Local\Temp
You may have to set your computer to show hidden files - when searching choose Tools > Folder Options, then in the View tab select "Show hidden files, folders and drives"

The file you're after will be called xmldata.xml and will be one of the most recent ones created so sort by date modified and look for that file.

Regards
Keith

Keith Maguire
South Australian Museum
useravatar
Offline
11 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How can Page Views be conditionally formatted?

Many thanks again, Keith!

I tried one other thing in the page view properties, and the department color-coding seems to work now, after changing one setting to treat the "SecDepartment_tab" as text:  Report--> Properties--> "Fields" tab--> highlight the department field & click "Table as Text" button)

Not sure if that's a good fix, though, so if you're up for taking a look, I put the xml on google drive (original + fixed xml, along with the corresponding html if it helps):

http://drive.google.com/file/d/0B9ciPt0 … jNDZVYtaVE
(forum wasn't accepting them as attachments here)

If you have any trouble accessing them, let me know, and again, major thanks for your help.
-kate

Kate Webbink
Information Systems Specialist
useravatar
Offline
10 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How can Page Views be conditionally formatted?

Hi Kate

Ah, looking at your example HTML showed how the example I was using wouldn't work - I've been enclosing everything in DIVs when working on my own page view so I was overly attached to that and it messes up the tables. I was also changing big lumps of the page instead of just the particular fields

The strategy you're working with totally works, but may end up being a bit laborious as you add tests for all the options.

What appears to work is again keeping the colours in the css named by department or event type. But using the XSL to change the class of the td to include the value exported from EMu.

So whereas normally the values tds in the table have the class "atomvalue", they get changed to instead read for example "Technology atomvalue"

I added a test to make sure that this is only done for the two fields of interest, this stops any values that appear in the other fields and coincidentally match the css classes from turning the table technicolor. There would be a reasonable chance of that happening, if the value was a sentence such as in the description each word would be added as a class to the td.

The attached file works with the xmldataFIX.xml file. You could get it to work with xmldataOld.xml if you needed to I reckon by tweaking line 324 - the xsl:when bit

(I say "it works" - I mean it worked for me when I tested it in Firefox, hopefully it also works for you in EMu)

As before, do let me know if it doesn't work or if it's nearly-but-not-quite-there

Regards
Keith

xsl-for-page-view.xsl

Keith Maguire
South Australian Museum
useravatar
Offline
11 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How can Page Views be conditionally formatted?

Hi Keith,
That works like a charm over here--Many thanks!  And apologies for the belated reply!

I'm realizing that multi-word values sharing the same first word are colored by the first word.  Probably means we should avoid spaces in values for that field, but so far that actually helps to color code related values...Happy accident!

Again, many thanks for the solution + explanation!
-Kate

Kate Webbink
Information Systems Specialist
useravatar
Offline
10 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.

Re: How can Page Views be conditionally formatted?

No worries Kate, glad to be able to help and delighted that it worked!
Keith

Keith Maguire
South Australian Museum
useravatar
Offline
11 Posts
Website 
Administrator has disabled public posting. Please login or register in order to proceed.
There are 0 guests and 0 other users also viewing this topic

Board Info

Board Stats
 
Total Topics:
598
Total Polls:
0
Total Posts:
1358
Posts this week:
4
User Info
 
Total Users:
830
Newest User:
Dominic Whitehead
Members Online:
3
Guests Online:
152