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 October 1st, 2004, 01:08 PM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default copy-of xsi namespace

hi all,

I have a question related to the copy-of function in xslt 2.0:

I would like to deep copy a piece of my source XML to a new XML file, without declaring all Namespaces of my source XML in my copied excerpt.

I know, I can make use of the xsl:copy-of function with the copy-namespaces attribute set to 'no'. Then, my targetnamespace is indeed copied, and other Namespace declarations of my source XML document (such as the foo NS) are omitted. However, I still would like to keep the xmlns:xsi Namespace declaration in the copied excerpt (as this would make the latter self-contained).

Does anyone knows how to do this? I provide an illustrative example below (the copied excerpt is shown in italic font).

Many thanks in advance
chris


source XML:
----------

<foo:wrapper xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<bar:excerpt xmlns:bar="http://bar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <bar:subject>blablabla</bar:subject>
    <bar:subject>blablabla</bar:subject>
    <dc:author xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >blablabla</dc:author>
  </bar:excerpt>

</foo:wrapper>

output XML:
----------

<bla:container xmlns:bla="http://bla" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<bar:excerpt xmlns:bar="http://bar" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <bar:subject>blablabla</bar:subject>
    <bar:subject>blablabla</bar:subject>
    <dc:author xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >blablabla</dc:author>
  </bar:excerpt>

</bla:container>





 
Old October 1st, 2004, 03:34 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

With copy-of the choices are all or nothing, I'm afraid. If you want to be more selective, you can do the copy using a recursive shallow copy, in which case you have more precise control over the namespaces:

<xsl:template match="*" mode="copy">
  <xsl:copy copy-namespaces="no">
    <xsl:copy-of select="namespace::xsi"/>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates mode="copy"/>
  </xsl:copy>
</xsl:template>

Michael Kay
http://www.saxonica.com/
 
Old October 2nd, 2004, 10:32 PM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

works perfect!
thanks!

chris






Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with xsi:SchemaLocation akshay144 XML 2 August 20th, 2008 05:40 AM
Changing namespace on copy rushman XSLT 2 November 12th, 2007 02:35 PM
Creating xsi:type as an attribute AjayLuthria XSLT 5 May 10th, 2007 09:49 AM
validateOnParse versus xsi:nil JaKKe XML 0 March 7th, 2006 07:23 AM
Namespace copy problem francislang XSLT 3 February 20th, 2006 01:07 PM





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