homepage Welcome to WebmasterWorld Guest from 54.205.197.66
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
if not contains check against list
alst




msg:3803044
 1:24 am on Dec 9, 2008 (gmt 0)

Hi, need an xml guru's help....
Am trying to write an xsl stylesheet that will take a dynamically created xml file and output a list of free workstations.

The xml file has the following structure,
<logged in>
<software>
<userid>#*$!</userid>
<ip>172.xx.xx.xx</ip>
</software>
<software>
...
</software>
</loggedin>

The xml file outputs anything between 1 and 30 odd <software> nodes every three minutes with individual static ip addresses dependent on whether the workstation at that ip has had recent activity.

I want to query this xml file and check against a known list of ip addresses with the xsl file and output a new html list of ip's that represent free workstations.

I have managed to sort of do this by writing the following

<xsl: if test="not(contains(ip,'172.AA.AA.AAA'))">workstation A free</xsl: if>

except it runs down the entire <loggedin> list and checks each ip and outputs the text,

so if there were 9 <software> nodes, it writes "workstation A free" 9 times....

I need to write something that checks the <loggedin> tree and queries

...if within this list there is no instance of ip 'x' output this text 'yyy'

and repeats this query for all of the known workstations ip's so I get a single list of free stations.

Any ideas?
Thanks.

 

httpwebwitch




msg:3803469
 4:15 pm on Dec 9, 2008 (gmt 0)

Welcome to WebmasterWorld, alst!

This seems to me like a poor candidate for XSLT

you could do the same thing much more easily using a server-side script to parse the XML into an array of IPs, then compare that array against another array of known IP addresses.

array A = parsed from XML
array B = your list of known IPs
for each B as B[i],
- if B[i] is not in A,
- - add B[i] to array C
output C

Then if you like you can output the results as XML for transformation into your HTML. Or just have your script output HTML instead.

Doing it that way is more efficient and scalable... easier to maintain, too. your CPU will thank you

alst




msg:3803759
 9:29 pm on Dec 9, 2008 (gmt 0)

fair enough, however server side arrays are a bit beyond me at the moment.

all of the xsl processing is being done on reasonably high end machines and is not a constantly refreshing process,

found using keys worked to do it in xsl,

see below.

thanks again,

al

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key match="/loggedin/software/ip" use="text()" name="list"/>
<xsl:template match="/">


<xsl:if test="string-length(key('list','172.xx.xx.xx'))=0">
free
</xsl:if>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved