Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 14th, 2008, 02:01 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
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
Reply With Quote
  #2 (permalink)  
Old March 14th, 2008, 02:18 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old March 14th, 2008, 02:46 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:38 AM.


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