Whats Best Way? Exclude some xml, turn other red if "low"

K

kmunderwood

I have an xml file that I get "As Is"
(at bottom of post)

I want to sort and exclude some elements, and
turn other child elements red, or its background.

I want it to look like this:

Tank Level Temperature
B05 535.91 22.22

I want 535.91 to turn red when under, let say 600
(Or its background)

I have tried techniques like:(Abbreviated)

<XML ID="data" SRC="c:\xml\index.xml"></XML>
<TABLE id="device" datasrc="#data" datafld="device">
<tr><td><span id="device" datafld="tag"></span></td></tr></TABLE>

This gives me all elements with the "tag" field
I want to ignore some "Tag"s

I have tried xsl, like this: (xsl:if match)
<xsl:for-each select="fieldgate/device">
<xsl:if match=".[tag='B01']">
<tr>
<td width="200"><xsl:value-of select="tag"/></td>
<td width="200"><xsl:value-of select="v1"/></td>
<td width="200"><xsl:value-of select="v4"/></td>

This gives me almost exactly what I want, except the "v1"(level)
turning red when under 600. This is easy, because I can just repeat the
table and change the "if match" to match the tank#

I tried other xsl, "for-each", xsl:choose, xsl:when test, like:
<xsl:for-each select="fieldgate/device">
<tr>
<td><xsl:value-of select="tag"/></td>
<xsl:choose>
<xsl:when test="v1 &lt; 600">
<td bgcolor="#ff00ff">
<xsl:value-of select="v1"/></td>
</xsl:when>
<xsl:eek:therwise>
<td><xsl:value-of select="v1"/></td>
</xsl:eek:therwise>
</xsl:choose>
<td><xsl:value-of select="v4"/></td>
</tr>
</xsl:for-each>

This works great, except it returns all of the "tags"
and does not sort, and looks like this:
(535.91 background cell is red,...and -0.01)
Tank Level Temperature
B05 535.91 22.22
B04 42567.36 22.81
B06 37265.17 21.94
_4..20mA-1 -0.01 blank

So, I have displayed it with ,<span>, "if match" and the
combo xsl:choose", "when test", xsl:eek:therwise, etc.

All do a nice job, but I need better control.
I am a newbie, but I am willing to learn, but not what seems like 10
different languages to build a simple web page from an xml document.

If someone can tell me a method that give me this control, I will go in
that direction.

I dont really need to become en expert, I need to make a web page and
move on to other projects.
I also need to use css or other means to affect the font size.

Any help will be greatly appreciated
The xml looks like this:

<?xml version="1.0" encoding="iso-8859-1" ?>
<fieldgate ser="6C000D010A0" tag="TTL Bulk Storage Farm" type="full"
devices="all">
<timezone>0</timezone>
<os_version>3.18</os_version>
<conf>FXA520-AA1A</conf>
<device id="11183312ee" tag="B05" type="HART">
<u4>°C</u4>
<v4>22.22</v4>
<dev>Cerabar S</dev>
<man>Endress+Hauser</man>
<u1>lb</u1>
<v1>535.91</v1>
<type>HART</type>
<unid>11183312ee</unid>
</device>
<device id="_4..20mA-2" tag="_4..20mA-2" type="INTRN">
<u>mA</u>
<tag>_4..20mA-2</tag>
<hlsts1>OK</hlsts1>
<v1>-0.01</v1>
<man>Endress+Hauser</man>
<unid>_4..20mA-2</unid>
</device>
</fieldgate>

Thank you,,,,Ken
 
P

Peter Flynn

I have an xml file that I get "As Is"
(at bottom of post)

I want to sort and exclude some elements, and
turn other child elements red, or its background.

I want it to look like this:

Tank Level Temperature
B05 535.91 22.22

I want 535.91 to turn red when under, let say 600
(Or its background)

I have tried techniques like:(Abbreviated)

<XML ID="data" SRC="c:\xml\index.xml"></XML>
<TABLE id="device" datasrc="#data" datafld="device">
<tr><td><span id="device" datafld="tag"></span></td></tr></TABLE>

Use XSLT.
This gives me all elements with the "tag" field

XML doesn't have fields. It has elements and attributes.
You have an element called "tag" *and* an attribute called "tag".
I'm assuming you mean the attribute, not the element, as your
example is missing the element "tag" in the first device.

[snip]
All do a nice job, but I need better control.
I am a newbie, but I am willing to learn, but not what seems like 10
different languages to build a simple web page from an xml document.

This XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="html"/>

<xsl:template match="fieldgate">
<table>
<tr>
<th>Tank</th>
<th>Level</th>
<th>Temperature</th>
</tr>
<xsl:for-each select="device">
<xsl:sort select="@tag"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</table>
</xsl:template>

<xsl:template match="device">
<tr>
<td>
<xsl:value-of select="@tag"/>
</td>
<xsl:choose>
<xsl:when test="v1 &lt; 600">
<td bgcolor="#ff00ff">
<xsl:value-of select="v1"/>
</td>
</xsl:when>
<xsl:eek:therwise>
<td>
<xsl:value-of select="v1"/>
</td>
</xsl:eek:therwise>
</xsl:choose>
<td>
<xsl:value-of select="v4"/>
</td>
</tr>
</xsl:template>

</xsl:stylesheet>

gives you this HTML fragment:

<table>
<tr>
<th>Tank</th>
<th>Level</th>
<th>Temperature</th>
</tr>
<tr>
<td>_4..20mA-2</td>
<td bgcolor="#ff00ff">-0.01</td>
<td></td>
</tr>
<tr>
<td>B05</td>
<td bgcolor="#ff00ff">535.91</td>
<td>22.22</td>
</tr>
</table>

which seems to meet your criteria.

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top