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 March 6th, 2009, 06:23 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default Remove root namespace help?

How do I remove the p prefix from the input document so that it doesn't occur in the output document? I tried exclude-result-prefixes="p" but that only removes it from the root element

Input xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<p:MyReq 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:_02="urn:iso:std:iso:20022:tech:xsd:something" 
    xmlns:p="http://somecompany/MyXSD">

  <RqUID>as</RqUID>
  <MsgRqHdr>
    <SomeInfo>
      <SomeOwner>Other</SomeOwner>
    </SomeInfo>
  </MsgRqHdr>
  <something>
    <_02:GrpHdr>
      <_02:MsgId>123456</_02:MsgId>
      <_02:NbOfTx>1</_02:NbOfTx>
    </_02:GrpHdr>
  </something>
</p:MyReq>
output xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<MyReq 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:_02="urn:iso:std:iso:20022:tech:xsd:something" 

  <RqUID>as</RqUID>
  <MsgRqHdr>
    <SomeInfo>
      <SomeOwner>Other</SomeOwner>
    </SomeInfo>
  </MsgRqHdr>
  <something>
    <_02:GrpHdr>
      <_02:MsgId>123456</_02:MsgId>
      <_02:NbOfTx>1</_02:NbOfTx>
    </_02:GrpHdr>
  </something>
</MyReq>
XSL attempt which is not finished
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:p="http://somecompany/MyXSD"
      exclude-result-prefixes="xs p"  
      version="2.0">
    
    <xsl:template match="p:MyReq">
        <MyReq xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:_02="urn:iso:std:iso:20022:tech:xsd:something">
            <xsl:apply-templates select="RqUID"></xsl:apply-templates>
            
        </MyReq>
    </xsl:template>
    
    <xsl:template match="RqUID" >
        <xsl:copy-of select="."></xsl:copy-of>
    </xsl:template>
       
</xsl:stylesheet>
 
Old March 6th, 2009, 06:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0, both xsl:copy and xsl:copy-of have an attribute copy-namespaces="no" which causes all "unused" namespaces to be dropped - that is, namespaces which are not used in the name of the element being copied, or in any of its attributes. This is probably sufficient to meet your requirement.

exclude-result-prefixes only affects namespaces declared in the stylesheet, not those copied from a source document.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 6th, 2009, 06:49 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

your so cool you know everything about this stuff. Thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove namespace prefix from XmlBean ratzko BOOK: Professional Java Development with the Spring Framework 0 August 10th, 2008 01:23 PM
why cannot remove aspx.vb files in root? badboy1 ASP.NET 3.5 Basics 5 June 25th, 2008 08:23 AM
Remove namespace from output file jopet25 XSLT 12 March 9th, 2007 11:12 AM
Square root Ashleek007 C++ Programming 3 December 12th, 2004 04:21 PM
Root Directory Chudz BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 July 11th, 2004 03:13 PM





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