LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-25-2018, 06:30 AM   #1
martijndutch
LQ Newbie
 
Registered: Aug 2018
Posts: 2

Rep: Reputation: Disabled
Calculate using XMLStarlet


Hi

I'm using xmlstarlet to transform my suppliers product list into a CSV. Now I want to add a column which is a calculated price with my upsell precentage on top of it. Can this be done using xmlstartlet? In the example below 'prijs' is MY price. I want to add a 'prijs' * 1.30.

xmlstarlet sel -t -m / -o "product_id;brand;product_name;stock;msrp;inkoopEx;prijs" -n -b -m /products/product -v product_id -o ";" -v brand -o ";" -v product_name -o ";" -v stock -o ";" -v msrp -o ";" -v prijs -o ";" -o ";" -n text.xml

example xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<products>
<product><product_id>18</product_id><product_name>N-Male &lt;&gt; SMA-RP Male 25 cm</product_name><stock>120</stock><msrp>8</msrp><prijs>4.5</prijs></product>
<product><product_id>19</product_id><product_name>RF240 N-Male &lt;&gt; SMA-RP Male 1 m</product_name><stock>26</stock><msrp>10</msrp><prijs>6.9</prijs></product>
<product><product_id>24</product_id><product_name>RJ45 CAT5e plug solid</product_name><stock>200</stock><msrp>0.25</msrp><prijs>0.18</prijs></product>
<product><product_id>25</product_id><product_name>RJ45 Ethernet Connector System</product_name><stock>0</stock><msrp>11</msrp><prijs>7</prijs></product>
<product><product_id>37</product_id><product_code>AC-18V-1A</product_code><product_name>AC adapter 18V 1A</product_name><stock>12</stock><msrp>10</msrp><prijs>5.69</prijs></product>
 
Old 09-27-2018, 01:29 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,235
Blog Entries: 3

Rep: Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710Reputation: 3710
According to the documentation -v is a shortcut for the value of the XPATH expression given, so the following should work:

Code:
-v "prijs * 1.30"
As in the following:

Code:
xmlstarlet sel -t -m / \
     -o "product_id;brand;product_name;stock;msrp;inkoopEx;prijs" \
     -n -b -m /products/product -v product_id -o ";" -v brand \
     -o ";" -v product_name -o ";" -v stock -o ";" -v msrp -o ";" \
     -v prijs -o ";" \
     -v "prijs * 1.30" -o ";" \
     -n text.xml
On a tangent, I wonder why these files do not use the ASCII control codes for Record Separator (1e) and Unit Separator (1f). Tab-delimited and, worse, comma-separated are very hard to parse. Using the right ASCII control codes would seem to make that easier but I've not seen programs do that. Perhaps it is M$ damage which has spread to the rest of the world?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate the value? Rizwanamalek Linux - Networking 1 04-08-2015 12:46 PM
How to calculate the parameater Rizwanamalek Linux - Networking 4 03-25-2015 01:02 AM
How to calculate Availability? xeon123 General 1 12-29-2014 01:19 PM
update xml file with xmlstarlet masonje Linux - General 1 05-28-2014 11:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration