|
Subject:
|
Remove namespace from output file
|
|
Posted By:
|
jopet25
|
Post Date:
|
3/7/2007 6:55:13 AM
|
Hi,
I am getting the namespace uri value in my output file. I am passing the text file as an input and the output is xml. I am new to xslt. The problem is when i use older version of both xerces and xalan it is working fine. But when i use newer versions of xerces and xalan (includes xercesimpl.jar & serializer.jar), i am getting namespace values.
Please suggest me how to get rid of this? Should i need to change anything in my XSL.
Thanks in advance, Peter.
|
|
Reply By:
|
mhkay
|
Reply Date:
|
3/7/2007 7:10:09 AM
|
It's very difficult to show people what's wrong with their code if they don't show you the code.
If you have an unwanted namespace in your output there are two main reasons. Either it was copied from the stylesheet, in which case you can often get rid of it using exclude-result-prefixes. Or it was copied from the source document using xsl:copy or xsl:copy-of. In 2.0 you can solve that using the copy-namespaces="no" option on those instructions. In 1.0 it's harder: instead of copying the elements, you need to rebuild them one by one using xsl:element.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
jopet25
|
Reply Date:
|
3/7/2007 7:21:37 AM
|
Thanks michale,
my xsl is
<?xml version="1.0" encoding="UTF-8"?> <!-- $Id: rpdeeds-x.xsl,v 1.14 2006/06/07 08:29:16 c001694 Exp $ --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://projects.int.westgroup.com/unity/morpheus" xmlns:morpheus="class:com.westgroup.morpheus.extensions.XSLTExtensions" xmlns:mi="http://projects.int.westgroup.com/unity/morpheus/xparser" exclude-result-prefixes="m morpheus mi">
<xsl:template match="r"> <xsl:if test="de.FA1080"> <xsl:apply-templates select="de.FA1080"/> </xsl:if> <xsl:if test="de.historical"> <xsl:apply-templates select="de.historical"/> </xsl:if> </xsl:template>
<xsl:template match="de.FA1080 | de.historical"> <xsl:if test="rec.typ='withdrawn'"> <xsl:apply-templates select="delete"/> </xsl:if> <xsl:if test="not(rec.typ='withdrawn')"> <xsl:call-template name="add"/> </xsl:if>
</xsl:template> <xsl:template name="add"> <n-document control="ADD">
<xsl:if test="/r/de.FA1080 | /r/de.historical">
<xsl:choose> <xsl:when test="/r/de.historical"> <xsl:attribute name="m:contextKey"> <xsl:value-of select="col.cd.orig"/> </xsl:attribute> <!-- This is for Dallas and Harris records which use NAS to get a GUID --> <xsl:attribute name="guid"> <xsl:variable name="legacy.id"> <xsl:value-of select="morpheus:padString(string(hist.parc.num), string('24'), string(' '))"/> </xsl:variable>
<!-- This is a secondary.id2 type in Aurora, so if the element doesn't exist we must put a '~' to prevent an empty GUID --> <xsl:variable name="secondary.id"> <xsl:value-of select="col.cd.orig"/> </xsl:variable> <xsl:variable name="secondary.id1"> <xsl:value-of select="hist.cnty.cd"/> </xsl:variable> <xsl:variable name="secondary.id2"> <xsl:value-of select="de.sl.d/@iso.d"/> </xsl:variable> <xsl:variable name="secondary.id3"> <xsl:value-of select="hist.doc.num"/> </xsl:variable> <!-- NOTE: field length is 6 bytes, but we have to account for expanded entity '&' so it's 64 --> <xsl:value-of select="morpheus:normalizeString(string($legacy.id))"/>
<xsl:choose> <xsl:when test="$secondary.id = ''"> <xsl:text>~</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$secondary.id"/> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test="$secondary.id1 = ''"> <xsl:text>~</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$secondary.id1"/> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test="$secondary.id2 = ''"> <xsl:text>~</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$secondary.id2"/> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test="$secondary.id3 = ''"> <xsl:text>~</xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="$secondary.id3"/> </xsl:otherwise> </xsl:choose> </xsl:attribute> </xsl:when> <xsl:otherwise>
<xsl:attribute name="m:contextKey"> <xsl:value-of select="col.cd.orig"/> </xsl:attribute> </n-document> </xsl:template> </xsl:stylesheet>
please give me your suggestions
|
|
Reply By:
|
mhkay
|
Reply Date:
|
3/7/2007 7:51:35 AM
|
So what's your output, and what namespace to you want to get rid of?
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
jopet25
|
Reply Date:
|
3/7/2007 7:59:49 AM
|
michael,
my output is
<?xml version="1.0" encoding="UTF-8"?> <n-load dataid ='REALDEEDS' notify ='West.PubRecsProdBuilder@thomson.com'> <n-document control="ADD" guid=" 04003~10903005G001~2003092220031015000001037367~" m:contextKey="04003" xmlns:m="http://projects.int.westgroup.com/unity/morpheus"></n-document> </n-load>
i want to get rid of namespace "m"
|
|
Reply By:
|
mhkay
|
Reply Date:
|
3/7/2007 8:25:08 AM
|
You can't get rid of the declaration of namespace m because your output includes an attribute in that namespace (m:contextKey). So before you can get rid of the namespace you need to either get rid of the attribute or put it in a different namespace.
Your code is explicitly creating that attribute:
<xsl:attribute name="m:contextKey"> <xsl:value-of select="col.cd.orig"/> </xsl:attribute>
so I don't know how you want to change it.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
jopet25
|
Reply Date:
|
3/7/2007 8:33:05 AM
|
hi michael,
but when i run the same xsl file with older version of xerces and xalan im getting the below output
<?xml version="1.0" encoding="UTF-8"?> <n-load dataid ='REALDEEDS' notify ='West.PubRecsProdBuilder@thomson.com'> <n-document control="ADD" guid=" 04003~10903005G001~2003092220031015000001037367~"></n-document> </n-load>
here the namespace doesnt appears. i want the same output while running using the newer versions of xerces and xalan (and xercesimpl, serializer)
|
|
Reply By:
|
jopet25
|
Reply Date:
|
3/8/2007 6:27:50 AM
|
anyone has any idea for this? If so please let me know.
Thanks in advance Peter.
|
|
Reply By:
|
mhkay
|
Reply Date:
|
3/8/2007 7:49:32 AM
|
It looks to me as if the earlier Xalan release wasn't outputting the m:contextKey attribute, presumably on the theory that its name is invalid (XSLT 1.0 allows the processor to drop an attribute with an invalid name). But that's wrong, it's name isn't invalid, it just uses a namespace which you've asked to exclude. The correct action is to output the attribute and the namespace, so it looks as if they fixed the bug. If you don't want the attribute to be output then get rid of the xsl:attribute instruction.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
jopet25
|
Reply Date:
|
3/8/2007 9:13:45 AM
|
Thanks much for your help Michael. I will try out this one.
|
|
Reply By:
|
jopet25
|
Reply Date:
|
3/9/2007 7:22:43 AM
|
Michael,
i tried that one, but in another xsl we do not have that as an attribute but we do have as below
<xyz m:id="_m32"> <xsl:value-of select="a.zip/c.zip"/> </xyz>
here 'm' is namespace.
this also gives the output with namespace value. do you have any idea how to get rid of these with newer versions of xerces & xalan
|
|
Reply By:
|
mhkay
|
Reply Date:
|
3/9/2007 7:44:56 AM
|
In the previous example you were outputting an attribute m:contextKey that caused the m namespace to be declared.
In this example you are outputting an attribute m:id that causes exactly the same effect, and the remedy is exactly the same.
I'm sorry I'm having so little success in explaining this to you.
Michael Kay http://www.saxonica.com/ Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|
Reply By:
|
jopet25
|
Reply Date:
|
3/9/2007 10:12:51 AM
|
Thank Michael,
I was considering these 2 in a different manner. But you are correct that both are attributes only. And thanks much for your help.
|