• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSLT to copy an XML document

 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want XSLT to produce a result document that is a copy of the input XML document. When I try:

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

I appear to get a result document which contains only the XML values (the XML version, namespaces, and XML tags in the body are missing).

Perhaps I have a defective XSLT IDE - I'm using EDITiX

If I can get this to work, then I'd like to be able to transform XML documents with changes but the resultant document should be XML not just values.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you are getting the correct output for that transformation. You are relying on the default processing rules for XSLT, which are basically that text nodes are copied to the output.

What you are looking for is called an "identity transformation"; it looks like this:

I would suggest you read a tutorial or a book about XSLT, rather than writing code based on guesses about how the language works. (Your other sin was to blame your IDE rather than assuming you were wrong. I always find that assuming it's my fault when things go wrong is a much more fruitful approach to solving problems.)
 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,


Thanks for that information.

I went through 2 XSLT tutorials but neither contained the information you conveyed in your response. The tutorials focus on what most beginning XSLT users need, namely the ability to extract textual information from an XML source and format/display it in a browser. Consequently they usually show the generation of HTML tags and xsl:value-of text.

I didn't blame my XML IDE, I merely suggested that it might be at fault.
Since I am an XSLT newbie I naturally suspect that any problem I might encounter using XSLT would be rooted in my ignorance, but after some fruitless experience with ButterflyXML I don't rule out the possibility of XML IDE malfunction.

I greatly appreciate your response and value your help now and possibly in the future.

Thanks,

John Davis
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I do have to admit, most of the XSLT "tutorials" I have seen on the web just rehash the XSLT elements and throw in a few trivial examples. Not very impressive in general. I learned XSLT by reading Michael Kay's XSLT book, which at least has some decent examples in it. Not to say there aren't other good XSLT books out there.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Davis

Have you tried this FAQ? ;)

http://bobcat.webappcabaret.net/javachina/faq/xslt_01.htm

Search for "identity" text, you will find two versions of Identity templates useful for different purposes.

Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic