|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
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> |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|