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 November 18th, 2003, 10:09 PM
kay kay is offline
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy xml-to-xml

I have a 2-step transformation requirement. first step goes just fine, transforming xml-to-xml using xslt. For step 2, I need to use the transformed xml of step 1 as input to create the final document. The final document needs to be fully tagged xml.

Using Mr. Kay's book as a guide, I coded an xslt with an xsl:copy-of. The output contained all the data, but no tags! So I decided to try xsl:copy using the example code on pg 194 of 2nd edition, as follows:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()" mode="copy">
    <xsl:copy>
        <xsl:apply-templates select="@*" mode="copy"/>
        <xsl:apply-templates mode="copy"/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>

Again, the result has no tags! [u]What do I need to do to get the tags copied from xml to xml?</u>

regards, kay
 
Old November 19th, 2003, 04:36 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I'm not sure what the point of your transformation is but two things, when you say no tags how are you viewing the result? In a browser if it doesn't recognise it as an xml document you'll just see the text between elements. Secondly the identity transform normally used is below, it copies everything and you can override for certain nodes by adding extra templates matching those nodes.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="node()|@*">

    <xsl:copy>

      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <!--
    Templates to match nodes that need changing go here
  -->
</xsl:stylesheet>
Joe (MVP - xml)
 
Old November 19th, 2003, 06:49 PM
kay kay is offline
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by joefawcett
 I'm not sure what the point of your transformation is but two things, when you say no tags how are you viewing the result? In a browser if it doesn't recognise it as an xml document you'll just see the text between elements. Secondly the identity transform normally used is below, it copies everything and you can override for certain nodes by adding extra templates matching those nodes.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:template match="node()|@*">

    <xsl:copy>
      
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <!--
    Templates to match nodes that need changing go here
  -->
</xsl:stylesheet>
Joe (MVP - xml)
regards, kay
 
Old November 19th, 2003, 06:51 PM
kay kay is offline
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your response. I was able to achieve what I needed by reversing my steps and using the document() function. I still need to figure out how to make document() respond to a variable that java code will manipulate. Thanks again! :)


Quote:
quote:Originally posted by joefawcett
 I'm not sure what the point of your transformation is but two things, when you say no tags how are you viewing the result? In a browser if it doesn't recognise it as an xml document you'll just see the text between elements. Secondly the identity transform normally used is below, it copies everything and you can override for certain nodes by adding extra templates matching those nodes.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:template match="node()|@*">

    <xsl:copy>
      
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <!--
    Templates to match nodes that need changing go here
  -->
</xsl:stylesheet>
Joe (MVP - xml)
regards, kay
 
Old November 19th, 2003, 06:55 PM
kay kay is offline
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One more thing, I think the biggest reason I was getting no tags (as viewed by xmlspy) was because of a namespace issue. The document I was trying to transform was of a different namespace, so all my matches were not matching. I added a namespace qualifier to all the node names of the input document, and suddenly things got much better. The parser was invoking the builtin templates, which dumped all the data, but none of the tags...

Quote:
quote:Originally posted by joefawcett
 I'm not sure what the point of your transformation is but two things, when you say no tags how are you viewing the result? In a browser if it doesn't recognise it as an xml document you'll just see the text between elements. Secondly the identity transform normally used is below, it copies everything and you can override for certain nodes by adding extra templates matching those nodes.
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:template match="node()|@*">

    <xsl:copy>
      
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
  <!--
    Templates to match nodes that need changing go here
  -->
</xsl:stylesheet>
Joe (MVP - xml)
regards, kay





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
Building a new XML > lost in copy-of-select and if akentanaka XSLT 2 June 30th, 2008 07:35 AM
xml invalid top level from ASP write XML(solution) g000we XML 0 August 9th, 2006 03:56 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
copy xml to xml (with java script) Umen XML 4 September 14th, 2004 06:51 AM





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