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 March 14th, 2008, 02:01 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default Changing the Source Document

I may be trying to use XSLT in the wrong way, but I'd like to modify the source document.

I can do this using perl or php with XML/XSLT/XPATH extensions, but I'd rather use XSLT natively because it's more intuitive for this kind of thing.

Basically, I want to use XSLT (well, mostly XPATH) as an intelligent search and replace tool for XML files.

I have this rather large XML file that was generated by Adobe Framemaker. I have another XML file with information in it that I need to merge into the Framemaker XML document. I want to search through the FM document, find a place where information needs to be merged, go get that from the other XML file and place it into the FM file.

I can see how to do it by writing to a 3rd, output document. Except I'd have to write rules for all the structure for the FM document, which means a ton of rules. I'd rather just update the FM document in place.

Is XSLT going to help me here, or should I just write a perl script with xpath extensions?

I hope I'm just missing something very fundamental.


------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old March 14th, 2008, 02:18 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can't modify a document in place with XSLT. You need to make a modified copy.

You don't need "a ton of rules". You just need one rule for all the elements that don't need to change:

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

supplemented by specific rules for the elements that do need to change.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 14th, 2008, 02:46 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

That looks pretty fundimental :)
I'll jump right on that and see if I can make it fly.

Thanks Michael!

- m

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
Return to source context after document('') jkmyoung XSLT 2 June 30th, 2007 03:04 AM
changing xml document object with javascript stekker XML 3 May 7th, 2006 08:29 AM
JAXP without source document Hendrik XSLT 1 September 28th, 2004 03:31 AM
changing Text source file names rjjhome SQL Server DTS 1 August 18th, 2004 02:27 PM
Changing source table of crystal report at runtime bhavanipodipireddy Crystal Reports 1 January 16th, 2004 08:35 AM





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