Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 17th, 2009, 08:39 AM
Registered User
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help needed to convert an XML file


I'm TOTALLY new to XML and need some help achieving something I'm sure is VERY simple to you all here....

I need to open an XML file my TV scheduling/recording software generates, read in some values and then output a new XML file in a new format using these values so my media center software can import the data.

Now I think XSLT is the way forward, but after much searching I just can't work out how to actually do this from a windows script.

So the source file looks like this;
 <?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
- <capture>
  <ws_filename>(2009-06-13 16-55) TEN News At Five TEN.mpg</ws_filename> 
  <ws_fullfilename>D:\TV_Recordings\general\(2009-06-13 16-55) TEN News At Five TEN.mpg</ws_fullfilename> 
  <ws_name>TEN News At Five</ws_name> 
  <ws_start>Sat Jun 13 16:55:00 EST 2009</ws_start> 
  <ws_stop>Sat Jun 13 17:40:00 EST 2009</ws_stop> 
- <epg_item>
  <epg_title>TEN News At Five</epg_title> 
  <epg_subtitle /> 
  <epg_description>A full half hour of news with extensive coverage of local, national and international news and weather. [Program info # Ten]</epg_description> 
  <epg_channel>Network TEN Sydney</epg_channel> 
  <epg_start>Sat Jun 13 17:00:00 EST 2009</epg_start> 
  <epg_stop>Sat Jun 13 17:30:00 EST 2009</epg_stop> 
  <epg_ratings /> 
  <epg_url /> 
And all I need to do is extract the appropriate fields and create this in an new file called "Original_Filename JRSideCar.xml"

 <LocalTitle>TEN News At Five<LocalTitle>
 <RunningTime>45 min</RunningTime>
 <Description>A full half hour of news with extensive coverage of local, national and international news and weather. [Program info # Ten]</Description>
Can anybody help me with this as I just don't know where to start??

Many thanks
Old June 17th, 2009, 08:49 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

Well it seems to you need to find some basic tutorials on how XSLT works, as this is quite basic. On the positive side you've correctly identified that XSLT will do what you want, which is a good start.

I'll post the following code, which hopefully you can digest and try to understand. I would recommend trying to understand each of the elements in this example so you can complete the rest of the solution yourself, rather than continuing to ask basic questions.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output indent="yes"/>
   <xsl:template match="capture">
            <xsl:value-of select="ws_name"/>
         <RunningTime><xsl:value-of select="ws_duration"/></RunningTime>
         <Description><xsl:value-of select="epg_item/epg_description"/></Description>
         <Genres><xsl:value-of select="epg_item/epg_category"/></Genres>
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Old June 17th, 2009, 08:53 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

I suggest you start with some online tutorials or one of Muchael Kay's books on XSLT.
It's not a language you can pick up as you go as it's a different way of doing things from that which most programmers are used to. The example you've shown is quite simple though and requires some literal elements and judicious use of xsl:value-of along wih the appropriate XPath needed to select the correct nodes. Here is a version 1.0 solution:

<xsl:value-ofselect="capture/epg_item/epg_title" />
<xsl:value-ofselect="capture/ws_duration" />
<xsl:value-ofselect="capture/epg_item/epg_description" />
<xsl:value-ofselect="capture/epg_item/epg_category" />
Old June 20th, 2009, 11:45 PM
Registered User
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for the replies,

I've managed to get my VB Script to use the msxml object and do the transformation using the above examples.

Many thanks

Similar Threads
Thread Thread Starter Forum Replies Last Post
Aurgent needed(VB convert to Java) debasisha Java GUI 1 December 5th, 2008 10:01 PM
Convert 1 big XML to multiple smaller XML victorcorey XSLT 1 March 20th, 2008 05:59 AM
Convert XML to XML template question bonekrusher XSLT 3 July 12th, 2007 07:47 AM
convert XML to XMl - Another Namespace question bonekrusher XSLT 2 July 10th, 2007 07:32 AM
biztalk convert a binary file to XML izakref Biztalk 0 March 15th, 2004 09:07 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.