XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 6th, 2002, 11:57 PM
sunnychan's Avatar
sunnychan sunnychan is offline
a lazy guy
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Hong Kong
Posts: 99 sunnychan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
XSL question

In the following XML, there is a ID_LIST and a USER_LIST.
The XSL below loop through the ID_LIST and try to find out whether the ID contains in the ID_LIST exist in USER_LIST or not.

In my XSL, it can show the ID if it is exist, but it cannot show the ID if it is not exist in the USER_LIST.

Anyone got a solution? Thanks.


XML:

<MyXML>
<ID_LIST>
<ID>1</ID>
<ID>22</ID>
<ID>5</ID>
</ID_LIST>
<USER_LIST>
<UID>5</UID>
<UID>17</UID>
</USER_LIST>
</MyXML>

XSL:
<xsl:for-each select="/MyXML/ID_LIST/ID">
<xsl:variable name="MYID">
<xsl:value-of select="./ID"/>
</xsl:variable>
<xsl:for-each select="/MyXML/USER_LIST/UID">
<xsl:if test="$MYID = .">
ID: <xsl:value-of select="$MYID"/> EXIST!
</xsl:if>
</xsl:for-each>
</xsl:for-each>

Reply With Quote
  #2  
Old May 20th, 2002, 03:52 PM
chinnman chinnman is offline
Fries w/ That?
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Kansas
Posts: 8 chinnman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SunnyChan--

Try This:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="/MyXML/ID_LIST/ID">
<xsl:variable name="MYID">
<xsl:value-of select="."/>
</xsl:variable>
<!--<xsl:for-each select="/MyXML/USER_LIST/UID">-->
<xsl:choose>
<xsl:when test="//USER_LIST/UID = $MYID">
<!-- EXIST! -->
<xsl:text>User ID exists: </xsl:text>
<xsl:value-of select="$MYID"/>
<xsl:text>
</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>User ID DOES NOT exist: </xsl:text>
<xsl:value-of select="$MYID"/>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
<!--</xsl:for-each>-->
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I commented out your nested loop and changed your <if> to a <choose> that just checks for existence of any UID with the current value. Attached is the xsl and text xml.

Hope this helps.

Chinnman
Attached Files
File Type: zip uid examp.zip (1.0 KB, 308 views)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway