472,805 Members | 937 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Can not combine "if match=" and "when test"

I am trying to combine "if match=" and "when test"
I am a newbie, and have made both work separately, but I can not seem
to combine them.
This is my xml("index.xml")page(I can not change this, it comes to me
this way.
<?xml version="1.0" encoding="iso-8859-1" ?>
- <fieldgate ser="6C000D010A0" tag="TTL Bulk Storage Farm" type="full"
devices="all">
<time>19700101-000000</time>
<timezone>0</timezone>
<ff_version>01.02.02-071 20050118</ff_version>
<os_version>3.18</os_version>
<conf>FXA520-AA1A</conf>
- <device id="11183312ee" tag="B05" type="HART">
<u4>C</u4>
<v4>22.22</v4>
<u2>In H2O</u2>
<dev>Cerabar S</dev>
<man>Endress+Hauser</man>
<u1>lb</u1>
<v1>535.91</v1>
<type>HART</type>
- <param>
<t1ch>Bulk Tank B5</t1ch>
<t2ch>Weight in Pounds</t2ch>
<max>43928.00</max>
<min>0.00</min>
</param>
</device>
</fieldgate>
The "device" element repeats 11 more times,(tag number changes) and I
want to ignore some,
so I am using an "if match".
I just repeat the table for each bulk tank that I want to display.
This is my "if match" xsl("index.xsl"):
It works, but I can not make a v1 under 2000, have the background
change color
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table width="800" border="2" bordercolor="#3300CC"
bgcolor="#0099CC">
<tr>
<th>Tank #</th>
<th>Current Level</th>
<th>Temp.</th>
</tr>
<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>
</tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
This shows an html page like this:
Tank # CurrentLevel Temp.
B01 395.47 69.65

I want the cell background to change to red when the level is below
2000
This is my "when test" xsl("index2.xsl"):
It works, but shows all tags, and I want to ignore some.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template
match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Tank</th>
<th>Level</th>
</tr>
<xsl:for-each select="fieldgate/device">
<tr>
<td><xsl:value-of select="tag"/></td>
<xsl:choose>
<xsl:when test="v1 &lt; 100">
<td bgcolor="#ff00ff">
<xsl:value-of select="v1"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="v1"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet>

This is my html:

<html>

<head>
<style type="text/css">
th, td { font-size: 200%; }
</style>

</head>
<body>
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("index.xml")

// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("index.xsl")

// Transform
document.write(xml.transformNode(xsl))
</script>

</body>
</html>
I have tried various combinations, to no avail.
If you can not help, can you suggest an article or suggestions on which
way to go?

Jul 20 '05 #1
5 2011


<xsl:if match

xsl:if does not have a match attribute it has a test attribute.
=".[tag='B01']">

You can't use [] predicates after .
just use
="tag='B01'"

David
Jul 20 '05 #2
OK, What can I use to get the controlled results that I am looking for?
Out of all of the ways to extract xml data and put it into a web page,
which should I learn to do?

Can I change the following xsl, and apply a "choose", and "when test"
to get only the tag='B01' to show up?
When I try to do this, the result is a "true" display in the column for
tag='B01', and a "false" for the other tags.
Can I trick it somehow?
I will learn whatever method will give me the controls I need.

Thanks, Ken

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template
match="/">
<html>
<body>
<h2>Bulk Storage Tanks</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Tank</th>
<th>Level</th>
<th>Temperature</th>
</tr>
<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:otherwise>
<td><xsl:value-of select="v1"/></td>
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="v4"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet>

David Carlisle wrote:
<xsl:if match

xsl:if does not have a match attribute it has a test attribute.
=".[tag='B01']">

You can't use [] predicates after .
just use
="tag='B01'"

David


Jul 20 '05 #3
> Can I change the following xsl, and apply a "choose", and "when test"
to get only the tag='B01' to show up?


most likely but you'd have to give some hint about the criterion that
you want to use.

I also note that in your sample posted earlier tag was an attribute of
device

but you have

<td><xsl:value-of select="tag"/></td>

which would select an element, so selects nothing in this case you need
@tag to select an attribute node.

David
Jul 20 '05 #4
OK, I want to
1. Only show the <tag> that want to, and
2. Turn an attribute a color when it falls below a certain level.
This is the way I want the html to display:
Tank Level Temperature
B05 535.91 22.22

535.91 background turns red, the way I need it to.
But, the way it pulls in all "Tag"
It looks like:
Tank Level Temperature
B05 535.91 22.22
B04 42567.36 22.81
_4..20mA-2 -0.01 <no data>
I want to ignore the _4..20mA-2, among others.
When the tank level falls below 600, I want the background or text to
turn red.
This is the way I get the xml.
(its abreviated. It is very long and shows 17 "Tag", or devices, but I
only want to show 12 of them)

The full xml file can be viewed here:
http://home.earthlink.net/~kmunderwood/index.xml

<?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>
This is the xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Tra*nsform"><xsl:templatematch="/">

<html>
<body>
<h2>Bulk Storage Tanks</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Tank</th>
<th>Level</th>
<th>Temperature</th>
</tr>
<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:otherwise>
<td><xsl:value-of select="v1"/></td>
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="v4"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template></xsl:styleshee*t>
This works fine, but includes all "tag", and I want to ignore some.
Tank Level Temperature
B05 535.91 22.22
B04 42567.36 22.81
_4..20mA-2 -0.01 Blank
The 535.91 background turns red, which is what I am looking for, but I
want to ignore <tag> _4..20mA-2
Plus, this way, it sorts all wrong.
I would like to show only 1 tank in the code, then I can repeat it in
separate tables and do whatever I want.

I had success displaying only the ones I wanted, using an "if match".
<xsl:if match=".[tag='B05']">, but I cant "test" on it.
This is the HTML:
<html>
<head>
<style type="text/css">
th, td { font-size: 200%; }
</style>
</head>
<body>
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDO*M")
xml.async = false
xml.load("index.xml")
// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDO*M")
xsl.async = false
xsl.load("index.xsl")
// Transform
document.write(xml.transformNo*de(xsl))
</script>
</body>
</html>

If can can give me a few a clues to work on,
I Thank You, Ken

David Carlisle wrote:
Can I change the following xsl, and apply a "choose", and "when test" to get only the tag='B01' to show up?
most likely but you'd have to give some hint about the criterion that
you want to use.

I also note that in your sample posted earlier tag was an attribute

of device

but you have

<td><xsl:value-of select="tag"/></td>

which would select an element, so selects nothing in this case you need @tag to select an attribute node.

David


Jul 20 '05 #5
This works fine, but includes all "tag", and I want to ignore some. That's because you select them all

<xsl:for-each select="fieldgate/device">
If you only want some of them, just select the ones you want, I can't
work out what that is but

<xsl:for-each select="fieldgate/device[not(starts_with(@tag,'_'))]">

wouldn't select those with a tag attribute starting with _ so
I want to ignore <tag> _4..20mA-2
for example.
I had success displaying only the ones I wanted, using an "if match".
<xsl:if match=".[tag='B05']">, but I cant "test" on it.


Not of you were using XSLT, a match attribute on xsl:if and a [
following a . are both fatal syntax errors and you would get no output.
You must have been using the Microsoft-specific transformation language
built in to IE5 (and supported in msxml3/IE6 for backwards
compatibility) The code you show however is in the XSLT namespace not
the namespace for that now deprecated language.

David
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Emmett | last post by:
The transform below should create a dropdown where the entry for "SSS Building I" is selected. (Or am I missing something? ) This transform creates the dropdown but doesn't do the select. Can...
3
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim...
1
by: kmunderwood | last post by:
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 ...
40
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the...
9
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual...
3
by: tldisbro | last post by:
Hello All, I am trying to use the returned value of the <fo:page-number> element/function in my <xsl:if> test condition. But am unsuccessful in doing so. Is it possible to use it in this fashion...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
2
by: riceyeh | last post by:
Hi, What does <xsl:if test="not($values)"mean? What I do not understand is $values? Here, means array? And . = $value means current node is equal to the variable value? So the total meaning is...
2
by: ericnyc | last post by:
Hi, I am a newbee in C++ Please review this is what I wrote , what so ever I understood so far, My question is that I have to " Write a program C++ array that reads in an integer number and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.