Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 July 30th, 2007, 06:06 AM
Registered User
 
Join Date: Jul 2007
Location: London, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT with output very similar to input

I need to convert a bunch of xml files to a format that is almost exactly the same as the original, ex:

<foo>
  <bar>text</bar>
  <foobar>
    <bar>text</bar>
  </foobar>
</foo>

becomes

<foo>
  <boff>text</boff>
  <foobar>
    <boff>text</boff>
  </foobar>
</foo>

This I thought would be trivial to do by applying an xslt to all of them, but is turning out to be a problem for me (I'm probably just missing some simple solution to this).

Is there a simple way to create a xslt that outputs exactly the same xml as the input except applies templates to a small set of element names?

Cheers!
Sindri
 
Old July 30th, 2007, 06:19 AM
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

Sure, there's a standard coding pattern for this. Write an identity template that copies elements unchanged:

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

and then override it for elements you want to modify:

<xsl:template match="bar">
  <boff>
    <xsl:apply-templates/>
  </boff>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 30th, 2007, 08:38 AM
Registered User
 
Join Date: Jul 2007
Location: London, , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That does the trick. Thanks!

Sindri




Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying DOCTYPE in input to the output xml mrame XSLT 3 July 31st, 2008 04:26 PM
Formating ListBox output to input into a file craigl Pro Visual Basic 2005 1 July 1st, 2007 08:02 AM
jsp - input/output - html?? tra77 JSP Basics 0 April 14th, 2006 04:35 AM
input:output file ct ASP.NET 1.0 and 1.1 Basics 1 September 27th, 2005 09:43 AM
input in html & output in jsp Befekadu Pro JSP 0 March 28th, 2005 10:28 AM





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