p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Changing the Source Document (http://p2p.wrox.com/showthread.php?t=66639)

mphare March 14th, 2008 02:01 PM

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

mhkay March 14th, 2008 02:18 PM

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-of select="@*"/>

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

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

mphare March 14th, 2008 02:46 PM

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

All times are GMT -4. The time now is 08:25 AM.

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