Subject: RE: [xsl] Getting rid of xmlns="" attributes From: "Allen, Erik" <eallen@xxxxxxxxxxx> Date: Wed, 31 Dec 2003 11:11:54 -0700 |
> -----Original Message----- > From: Lars Huttar [mailto:lars_huttar@xxxxxxx] > Sent: December 30, 2003 7:34 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] Getting rid of xmlns="" attributes > > If I understand you right, the source XML elements have no > namespace, and you want the result XML elements to be in no > namespace. However, The original XML looks like this: <?xml version="1.0" encoding="utf-8" ?> <template version="3" readVersion="3" xml:space="preserve"> <exportTimeStamp> <date>2003-12-29</date> <time>15:31:34</time> </exportTimeStamp> <templateInfo name="" id="1139410602" revision="1"> ... </templateInfo> ... </template> So, as you can see, there is no namespace. > > > I need > > to add two namespaces to the XML. > > I take this to mean you want to add two namespace > declarations to the output, > "http://tempuri.org/FormSchema.xsd" > and > "http://www.w3c.org/2001/XMLSchema-instance" > > Clearly the desired prefix for the latter is "xsi", > and you've got that covered. > But what prefix do you want for the former? And what > elements do you want to be in that namespace? > In your stylesheet you're using the null prefix, > i.e. you're making "...tempuri.org..." the default namespace. That is correct. The "http://tempuri.org/FormSchema.xsd" is supposed to be the default namespace so I don't have a prefix for it. > As a result, your output <template> element is in > this "...tempuri.org..." namespace (because result tree > elements with no namespace prefix go in the stylesheet's > default namespace). Is that what you wanted? > Did you want the other elements to be in that namespace too? I want it all in that namespace. [snip] > > I've found that if I change the namespace in the > > <xsl:stylesheet> from xmlns to xmlns:y, then I don't get the rogue > > attribute, > > That makes sense. You no longer have a non-null default namespace, > so there is no need to override the default namespace to produce > elements that are in no namespace. > > > but that is also giving me the incorrect namespace. > > Here is where I would need more specifics to understand what you want. > Which elements have the incorrect namespace and what namespace > did you want them to have? > > (Terminology precision check ... do you mean the namespace is incorrect, > or a namespace declaration, or a namespace prefix?) > > Do you want all of the output XML to be in no namespace? all > in the tempuri namespace? some of each? > If the latter, what namespace prefix do you want used for each? > You can't use "" as a prefix for two different namespaces, > unless you put xmlns="..." in multiple places. > I will confess that I'm not totally comfortable with namespace terminology so I may have been using incorrect terms. The original XML file has no namespace, even though everyone agrees it should have. However, due to legacy reasons, we can't add one in. (XPaths would then require the namespace prefix within every element name, which would require changing a lot of code which would then no longer work with older XML files.) For the "Terminology precision check", I believe I mean that the namespace prefix is incorrect. The URL within the namespace looks exactly how I want it, but I also want it to be the default namespace, not an explicit one. I want the output XML to be within the tempuri namespace, same as the root element is. From the comments I've been getting back, I believe I have solved my problem. I changed the stylesheet to look like this: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns="http://tempuri.org/FormSchema.xsd" xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance" version = '1.0'> <xsl:output method="xml"/> <xsl:template match="/template"> <template> <xsl:attribute name="version"> <xsl:value-of select="@version"/> </xsl:attribute> <xsl:attribute name="readVersion"> <xsl:value-of select="@readVersion"/> </xsl:attribute> <xsl:apply-templates select="*"/> </template> </xsl:template> <xsl:template match="node()"> <xsl:element name="{local-name()}" namespace="http://tempuri.org/FormSchema.xsd"> <xsl:apply-templates select="@*|node()|text()"/> </xsl:element> </xsl:template> <xsl:template match="@*|text()" priority="3"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet> This seems to have solved all the problems. The xsl:copy-of was preserving the namespace, so I have to explicitly write out the elements with the correct namespace. I apologize for not stating the XSL processor I'm using. I'm personally using Saxon 6.2.2 for my testing. The person who will be actually running this stylesheet is using the Microsoft .NET version. Since both were showing the same problem, I assumed it was common to all XSL processors. Thanks for all the help! Erik Allen XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Getting rid of xmlns="" a, Michael Kay | Thread | [xsl] newbie question on formatting, Renzo |
RE: [xsl] newbie question on format, Michael Kay | Date | [xsl] XPath Question, Kyle Partridge |
Month |