473,385 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

xsl: How to update varial value in a loop

13
I have a xml file:
Expand|Select|Wrap|Line Numbers
  1. <E1MBXYI SEGMENT="1">
  2. ...
  3. <CHARG>1000024187</CHARG> 
  4. ...
  5. </E1MBXYI>
  6. <E1MBXYI SEGMENT="1">
  7. ...
  8. <CHARG>1000024187</CHARG> 
  9. ...
  10. </E1MBXYI>
  11. <E1MBXYI SEGMENT="1">
  12. ...
  13. <CHARG>1000024188</CHARG> 
  14. ...
  15. </E1MBXYI>
  16.  
I want to transform it to another xml file, where I should only take the item CHARG if it has a differetn value.
I wrote the following code:
Expand|Select|Wrap|Line Numbers
  1. <DataArea>
  2.         <xsl:variable name="V_MaterialLot" select="''"/>
  3.         <xsl:for-each select="E1MBXYI">
  4.                 <xsl:if test="$V_MaterialLot != CHARG">
  5.                         <MaterialInformation>
  6.                                 <ID>
  7.                                         <xsl:value-of select="CHARG"/>
  8.                                         <xsl:variable name="V_MaterialLot" select="CHARG"/>
  9.                                 <ID>
  10.                         <MaterialInformation>
  11.                 </xsl:if>
  12.         </xsl:for-each>
  13. </DataArea>
  14.  
However, I can not define the varial V_MaterialLot twice in the same xsl.
Does someone have a solution to me?
Regards
maxin
Jan 28 '09 #1
3 2041
Dormilich
8,658 Expert Mod 8TB
if you want to use only the unique <CHARG>s, then you can try Muenchian Grouping before doing the output.
Jan 28 '09 #2
jkmyoung
2,057 Expert 2GB
More specifically it would be like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="E1MBXYI[not (CHARG = preceding-sibling::E1MBXYI/CHARG)]">
  2.  
No variables needed.
Jan 28 '09 #3
maxin
13
Thanks all for the solution.
I will try it.

Regards maxin
Jan 28 '09 #4

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

Similar topics

1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
4
by: Fredrik Henricsson | last post by:
Hey, I'm building an ontology in Protégé and I want to transform parts of it (e.g. the instances) to HTML with XSL. When I was transforming another file with 'simple' XML-tags like <author> before,...
6
by: Jody Gelowitz | last post by:
I have run into an issue with variable scope within an XSLT document that is translated in VS.NET 2.0. Under VS.NET 1.1 (XslTransform), this code works fine. However, when using VS.NET 2.0...
1
by: sommarlov | last post by:
Hi everyone >From one of our systems an xml file is produced. I need to validate this file before we send it to an external system for a very lenghty process. I cannot change the xml file layout....
5
by: the_jos | last post by:
Dear reader, I am trying some things with xml/xsl and cannot find a solution for what I would like to do. I have 2 base items with name and price and two that are composed of base two (given...
1
by: MORALBAROMETER | last post by:
Hi all, I want to update MULTIPLE elements of an HTML page using Ajax. for this reason i my response is an xml document. I want to use XSL at the client side to update these elements. How can i...
0
by: super.raddish | last post by:
Greetings one and all, I have a single source XML file and I am parsing the "records" within it into separate XML files using xsl:result-document. All that works fine. I am using the Saxon...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
9
by: shakilalig | last post by:
Hi All, I am writing an XSL to transform the XML to XML.Only change i need in xml is to add the value for the price element under book tag for which publisher location is "World". The...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.