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 July 31st, 2007, 08:40 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default Omit xmlns

Hello all,
I have few issues related with XSLT and would appreciate if somebody from group can guide me.

I've written a style sheet to transform one xml to another xml, wherein I am adding the

"xmlns:aid="http://ns.xxx.com/Metayy/4.0/" to my <root> element.

Something like below:

<root xmlns:psq="http://ns.xxx.com/Metayy/4.0/" psq:tye="bsk" psq:tps="tcs">.

I do not found any problem in adding the namespaces to the original xml but when I need to retransform this xml to the original, I’m unable to remove the “xmlns:psq” from it. Although there are no issues in removing the other namespaces ( psq:tye="bsk" and psq:tps="tcs") globally from the xml document, but the first namespace declaration remains intact even after transformation.

I’ve tried exclude-result-prefixes=”” to get the desired output but seems to be in vain. Can somebody let me know whether using exclude-result-prefixes=”” can resolve my trouble?

My second issue is to convert all the UTF entities back to corresponding Unicode values. I hope this can be achieved from XSLT itself, instead of using other conversion tool, which is least desirable.

Any guidance in this regard will be highly appreciated.

Pankaj


__________________
Pankaj
 
Old July 31st, 2007, 09:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can't tell what's wrong with your code without seeing your code.

Generally the rule is that with xsl:copy, namespaces are copied from the source document; with literal result elements, they are copied from the stylesheet. If you want to copy an element without its namespaces, use xsl:element name="{name()}" namespace="{namespace-uri()}">. exclude-result-prefixes only affects namespaces copied from the stylesheet, not those copied from the source document.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 31st, 2007, 09:47 AM
Authorized User
 
Join Date: Jul 2007
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi Michael
Thanks for quick response.

This is my root element. Frankly speaking I've never ever had any requirement for removing the xmlns, that's the reason I am struggling with it. Can you throw some on it.

Thanks in advance.

<root xmlns:psq="http://ns.xxx.com/Metayy/4.0/" psq:tye="bsk" psq:tps="tcs">
</root>

Below is my style sheet.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="*|@*">
      <xsl:choose>
      <xsl:when test="name()='psq:tye'">
      </xsl:when>
      <xsl:when test="name()='psq:tps'">
      </xsl:when>

<xsl:when test="name()='char'">
      </xsl:when>
     <xsl:otherwise>
    <xsl:copy>
        <xsl:apply-templates select="text()|*|@*"/>
        </xsl:copy>
     </xsl:otherwise>
     </xsl:choose>
</xsl:template>

</xsl:stylesheet>

 
Old July 31st, 2007, 10:18 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's like I thought, you are copying the element with xsl:copy and this copies all the namespaces. In XSLT 2.0 you can set copy-namespaces="no", but in 1.0 you have to change from xsl:copy to xsl:element.

You're not using template rules to good advantage. Instead of adding an xsl:choose into your identity template with conditions like <xsl:when test="name()='char'">, define additional template rules, in this case <xsl:template match="char">.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to omit the duplicate values when displayin ppakala XSLT 1 June 24th, 2008 06:13 PM
Sorting number, but omit null victorcorey XSLT 9 December 31st, 2007 02:45 PM
XMLNS mathias XML 0 February 20th, 2007 04:46 AM
omit-xml-declaration dextermagnific XSLT 3 August 4th, 2006 09:55 AM
Omit negative values in Queries - Access 97 snoopy92211 Access VBA 1 October 13th, 2004 12:24 PM





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