473,503 Members | 6,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to reference values from outer loop??

7 New Member
Hi,
I am working on an XSL stylesheet and I have a loop within a loop where I need to compare element values from the inside loop to values from the outer loop (see bolded line in XSL below). The inside loop references elements from a second XML document, which makes this especially difficult (at least difficult for me).
The outermost (first) loop references elements in the Primary XML file (the one to which the XSL is applied directly) and the inner loop references elements in the Second XML file.

Hopefully this makes sense...

Thank you so much!!
Christine


XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="file2" select="document('C:\Documents and Settings\e\My Documents\Trial XML\Recipe Code\UP_X783X_UFDF_CLEANING.XML')"/>
<html>
<body>
<table border="0" width="100%">
<tr align="left">
<th>Step</th>
<th>Parameter</th>
<th>Origin</th>
<th>Low</th>
<th>Value</th>
</tr>
<xsl:for-each select="RecipeElement/Steps/Step">
<xsl:sort select="@YPos" data-type="number"/>
<xsl:sort select="@XPos" data-type="number"/>
<xsl:for-each select="FormulaValue">
<tr>
<td>
<xsl:value-of select="ancestor::Step/Name/text()"/>
</td>
<td>
<xsl:value-of select="Name"/>
</td>
<xsl:if test="Value">
<td>Value</td>
<xsl:if test="Real">
<xsl:for-each select="$file2/RecipeElement/Parameter">
<xsl:if test="matches('Name/text()','FormulaValue/Name/text()=current()')"> <td>
0
</td>
</xsl:if>
</xsl:for-each>
<td>
<xsl:value-of select="Real"/>
</td>
<td>
High
</td>
</xsl:if>
</xsl:if>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Primary XML:
<?xml version="1.0" encoding="UTF-8"?>
<RecipeElement>
<Step XPos="600" YPos="598" AcquireUnit="true">
<Name>UP_X783X_UFDF_CLEANING:1</Name>
<StepRecipeID>UP_X783X_UFDF_CLEANING</StepRecipeID>
<UnitAlias>UP_X783X_UFDF_CLEANING:1</UnitAlias>
<FormulaValue>
<Name>CIP_FEED_PUMP_SPEED</Name>
<Display>false</Display>
<Value/>
<Real>75</Real>
<EngineeringUnits/>
</FormulaValue>
<FormulaValue>
<Name>CIP_XFER_PUMP_SPEED</Name>
<Display>false</Display>
<Value/>
<Real>35</Real>
<EngineeringUnits/>
</FormulaValue>
</Step>
</RecipeElement>


Second XML:
<?xml version="1.0" encoding="UTF-8"?>
<RecipeElement>
<Parameter>
<Name>CIP_FEED_PUMP_SPEED</Name>
<ERPAlias/>
<PLCReference>1</PLCReference>
<Real>45</Real>
<High>100</High>
<Low>0</Low>
<EngineeringUnits>%</EngineeringUnits>
<Scale>false</Scale>
</Parameter>
<Parameter>
<Name>CIP_XFER_PUMP_SPEED</Name>
<ERPAlias/>
<PLCReference>1</PLCReference>
<Real>30</Real>
<High>100</High>
<Low>0</Low>
<EngineeringUnits>%</EngineeringUnits>
<Scale>false</Scale>
</Parameter>
</RecipeElement>
Jul 17 '07 #1
1 2567
jkmyoung
2,057 Recognized Expert Top Contributor
Strangely enough, I had this problem 2 weeks ago. Before the for-each, create a variable pointing to your current location. Then reference that variable. In your case, you could simply make a variable pointing to the value of the Name element.

Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="Real">
  2. <xsl:variable name="Name" select="Name"/>
  3. <xsl:for-each select="$file2/RecipeElement/Parameter">
  4. <xsl:if test="matches('Name/text()',$Name)">  <td>
  5.  
  6. </td>
  7. </xsl:if>
Further simplifying, you could do this check in the for-each loop
Expand|Select|Wrap|Line Numbers
  1. <xsl:if test="Real">
  2. <xsl:for-each select="$file2/RecipeElement/Parameter[Name = current()/$Name]">
  3. <td>
  4.  
  5. </td>
  6. </xsl:if>
Jul 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1225
by: Squeamizh | last post by:
This is something that has been bothering me for a while. Assume the following two class definitions: class Inner { int a; int b; ... };
2
3625
by: Chaz | last post by:
Hello, I hope someone can help me out. I am going to be taking the third step in a programming class soon(I took the previous two a while ago at a different school) and in an effort to get back up...
6
8998
by: Thomas Beutin | last post by:
Hi, i've a speed problem withe the following statement: SELECT DISTINCT pz.l1_id, pz.l2_id, pz.l3_id, pz.l4_id FROM ot_adresse AS a, ot_produkt AS p LEFT OUTER JOIN ot_kat_prod AS pz ON (...
0
2295
by: Stephen Cairns | last post by:
I have the following rpx file in a .Net solution and I am getting the following build errors which are driving me crazy and ive no idea where I have went wrong. The build errors I'm getting are as...
2
1227
by: Jeff User | last post by:
I want to convert each record read (with a datareader) to a string array and then place each of those arrays into another array (sResult) The problem here is that when the inner loop begins to...
8
2456
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
8
2817
by: Fabian Braennstroem | last post by:
Hi, I would like to remove certain lines from a log files. I had some sed/awk scripts for this, but now, I want to use python with its re module for this task. Actually, I have two different...
68
4551
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
275
12035
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
7194
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7070
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.