Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 March 6th, 2007, 01:20 PM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default Apply changes to more than one file

I am trying to apply changes to more than 50 XML files. They all use the same tags.
I need to add 3 lines after the tag </book> in all the xml files.

Any ideas will help.
Thanks.

 
Old March 6th, 2007, 01:32 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

use xslt.



 
Old March 6th, 2007, 01:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0 (Saxon):

<xsl:template name="main">
  <xsl:apply-templates select="collection('file://c:/temp/?select=*.xml')"/>
</xsl:template>

<xsl:template match="/">
  <xsl:result-document href="{document-uri(.)}.out">
    <xsl:apply-templates/>
  </xsl:result-document>
</xsl:template>

<xsl:template match="*">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<xsl:template match="book">
  <xsl:next-match/>
  new line 1
  new line 2
  new line 3
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 6th, 2007, 01:47 PM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mike. This should make my chanegs a lot easier.
One question though, I have used applications like (OxygenXML) to transform one XML document, how can I use your style sheet to apply changes on all 50 files? Is there any way I can use a command line to make all the changes.

Thanks again,
Bill


 
Old March 6th, 2007, 01:52 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't use Oxygen myself - it might need a bit of tweaking, e.g. I don't know if Oxygen allows you to enter a stylesheet at a named template. But it's easy enough to run from the command line.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 6th, 2007, 02:01 PM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry Mike. But can you please at least tell me how to run in it using a command line. what would be the parameters? for example, a folder with all xml files.




 
Old March 6th, 2007, 02:05 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Michael,

suppose I have a <date> element in about 300 XML files. How do I change the value of the <date>...

I know that I might need to do this. bcogney's question trigger this one.

Thanks,

 
Old March 6th, 2007, 02:11 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default


java -jar saxon8.jar -it main stylesheet.xsl

More details at

http://www.saxonica.com/documentatio...mmandline.html

I set it up to read all files *.xml from a directory c:\temp, you will obviously want to change that. You'll probably want to change the calculation of an output file name in the xsl:result-document @href attribute - it was just a sketch for you to start with.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 6th, 2007, 02:12 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>suppose I have a <date> element in about 300 XML files. How do I change the value of the <date>...


Sounds like exactly the same question to me. What part of the answer don't you understand?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 6th, 2007, 02:25 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Since I am not adding a lines but rather changing the value.. would it be:

Code:
<xsl:template match="date">
<xsl:text>2008-06-06</date>
</xsl:template>
or would it be

Code:
<xsl:template match="date">
  <xsl:next-match/>
2008-06-06
</xsl:template>
I am not sure...





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to apply CSS to XSLT file??? rakesh XSLT 1 July 25th, 2008 03:20 AM
Apply a propertie file to a different xml file Clyne XSLT 5 January 2nd, 2007 10:56 AM
Templates Won't Apply neilac333 XSLT 5 October 26th, 2006 01:39 PM
Input type=file apply a filter?? italiansensation ASP.NET 1.x and 2.0 Application Design 3 May 24th, 2006 04:06 AM
Apply Custom template & import data from text file shampabera Excel VBA 2 August 8th, 2005 07:41 AM





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