LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-11-2009, 04:22 PM   #16
pg99
Member
 
Registered: May 2008
Location: UK
Distribution: Slackware
Posts: 73

Rep: Reputation: 18

I see, so you're trying to always get the barcode first because then it will always be in the merged field.

You could easily merge the 2 fields with a slight mod to the stylesheet, for example using:
Code:
<ItemTitle>
  <xsl:value-of select="ItemBarcode"/>
  <xsl:value-of select="ItemTitle"/>
</ItemTitle>
instead of
Code:
<xsl:copy-of select="ItemBarcode"/>
<xsl:copy-of select="ItemTitle"/>
XSLT is tailor-made for messing about with XML without resorting to writing your own parser. On windows you can easily run transforms with a bit of javascript or vbscript run through windows script host. there's tons of examples out there, I bet there's some stuff on w3schools about it...
 
Old 06-11-2009, 04:35 PM   #17
pg99
Member
 
Registered: May 2008
Location: UK
Distribution: Slackware
Posts: 73

Rep: Reputation: 18
Just had a quick google around and you can still get MS's command-line program to run the transformations from http://msdn.microsoft.com/en-us/library/aa468552.aspx. Then its as easy as: MSXSL –o out.xml in.xml reformat.xsl
 
Old 06-12-2009, 10:35 AM   #18
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Quote:
Originally Posted by ghostdog74 View Post
beautiful as a one liner. not beautiful when you want to decipher it
That is a neat line. Looking back I should've tried something like it myself. I almost did, but I decided to try my hand at awk instead (I've just finished reading through the Unix Grymoire and I'm trying to learn more about both programs).

The nice thing about it is that it uses the little-known sed hold buffer. To break it down, assuming I'm reading it correctly, the first part of the command matches the line '<ItemTitle>', then grabs the next line following it as well (the N command), stores them both in the hold buffer (h), and deletes the pattern space so that it can go on to the next command (d). The second expression then matches the <ItemBarcode> line and appends the contents of the hold buffer to it (G). That's it.

Actually, I think the real reason I went with awk was that I was having a bit of trouble understanding exactly how sed's hold buffer works in practice. This real-world example has helped a lot.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Substitute specific lines with lines from another file rahmathullakm Programming 4 01-10-2009 05:47 AM
How to modify a field in few lines in a file and save the new file - in Perl rounak94 Programming 1 10-02-2008 07:43 PM
How to rearrange partitions on a disk? sheintze Linux - Software 3 03-10-2007 07:39 PM
Random file lines directed to a new file. In script an error. In command line no err leventis Programming 1 09-28-2006 07:16 AM
can't rearrange desktop icons - kde arch23 Fedora 1 01-01-2004 11:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:08 PM.

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