 |
| 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
|
|
|
|

March 7th, 2007, 07:55 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Remove namespace from output file
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.
|
|

March 7th, 2007, 08:10 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

March 7th, 2007, 08:21 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks michale,
my xsl is
<?xml version="1.0" encoding="UTF-8"?>
<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.exten sions.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>
<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>
<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
|
|

March 7th, 2007, 08:51 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

March 7th, 2007, 08:59 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
michael,
my output is
<?xml version="1.0" encoding="UTF-8"?>
<n-load dataid ='REALDEEDS' notify =' [email protected]'>
<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"
|
|

March 7th, 2007, 09:25 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

March 7th, 2007, 09:33 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 =' [email protected]'>
<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)
|
|

March 8th, 2007, 07:27 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
anyone has any idea for this? If so please let me know.
Thanks in advance
Peter.
|
|

March 8th, 2007, 08:49 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

March 8th, 2007, 10:13 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks much for your help Michael. I will try out this one.
|
|
 |