Subject: RE: XSLT and Default namespaces From: "Evan Lenz" <elenz@xxxxxxxxxxx> Date: Thu, 5 Oct 2000 17:47:07 -0700 |
This raises an important issue for me, which I think was brought up fairly recently. One of the promises of XSLT was the ability to generate or transform XSLT stylesheets using XSLT. <xsl:namespace-alias/> works well for this, but the writers of the spec did not go far enough. There are no functions or instructions that will let me reliably construct QNames in the resulting tree. Sure, element and attribute names can be reliably qualified with the appropriate prefix, but not attribute *values*, as are needed in match patterns, etc. I don't see anything about this in the XSLT 1.1 Requirements document. Consider the following stylesheet: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xyz="http://xyzfind.com/schemas/xyzql/1.0"> <xsl:namespace-alias stylesheet-prefix="out" result-prefix="xsl"/> <xsl:template match="/"> <out:stylesheet version="1.0"> <out:template match="xyz:document"> <!-- stuff --> </out:template> </out:stylesheet> </xsl:template> </xsl:stylesheet> The above example will work fine if the stylesheet processor happens to output a namespace declaration using the prefix "xyz". But if it decides to use "abc" instead, which it has every right to do, the match attribute will still be "xyz:document", which would be invalid. This is all I need: <out:template match="{qname(xyz:document)}"> The qname() function, or something like it, would also be necessary for generating XML Schemas too, I believe. For generating stylesheets or schemas from scratch, this works fine, but for transforming an existing one, where QNames already exist in attribute values (or text content?) in the source, the problem is a bit more severe. While it wouldn't seem like much to ask the XSLT processor to generate a QName, it seems like a lot more for it to recognize one that's in the source tree. Any thoughts? Evan Lenz elenz@xxxxxxxxxxx http://www.xyzfind.com XYZFind, the search engine *designed* for XML Download our free beta software: http://www.xyzfind.com/beta -----Original Message----- From: Evan Lenz [mailto:elenz@xxxxxxxxxxx] Sent: Thursday, October 05, 2000 5:32 PM To: xsl-list@xxxxxxxxxxxxxxxx Subject: RE: XSLT and Default namespaces If an element or attribute in the source document is in a namespace (whether default or prefixed), your stylesheet *must* include a namespace declaration corresponding to the same namespace and it *must* use a prefix as well (whatever you want). Even if your stylesheet itself has a default namespace, that namespace will only be in effect for unprefixed element names in the stylesheet, but not for names in XPath expressions or XSLT patterns. <snip href="http://www.w3.org/TR/xslt#qname" note="emphasis added"> 2.4 Qualified Names The name of an internal XSLT object, specifically a named template (see [6 Named Templates]), a mode (see [5.7 Modes]), an attribute set (see [7.1.4 Named Attribute Sets]), a key (see [12.2 Keys]), a decimal-format (see [12.3 Number Formatting]), a variable or a parameter (see [11 Variables and Parameters]) is specified as a QName. If it has a prefix, then the prefix is expanded into a URI reference using the namespace declarations in effect on the attribute in which the name occurs. The expanded-name consisting of the local part of the name and the possibly null URI reference is used as the name of the object. ***The default namespace is not used for unprefixed names.*** </snip> Evan Lenz elenz@xxxxxxxxxxx http://www.xyzfind.com XYZFind, the search engine *designed* for XML Download our free beta software: http://www.xyzfind.com/beta -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxx]On Behalf Of Raimond Brookman Sent: Thursday, October 05, 2000 12:03 PM To: xsl-list@xxxxxxxxxxxxxxxx Subject: XSLT and Default namespaces Hi, I want to transform an xml document that has declared a namespace, for example: <?xml version="1.0" encoding="UTF-8"?> <test xmlns="myns"> <a> <b></b> </a> </test> The corresponding XSLT is: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:copy-of select="a/b"/> </xsl:template> </xsl:stylesheet> The resulting output document is empty. When i dont use a default namespace and prefix the root elements in the source document, and also declare the namespace in the XSL and use it in my X-path, it works: <?xml version="1.0" encoding="UTF-8"?> <x:test xmlns:x="myns"> <a> <b></b> </a> </x:test> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="myns"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <xsl:copy-of select="x:test/a/b"/> </xsl:template> </xsl:stylesheet> Result: <?xml version="1.0" encoding="UTF-16"?> <b xmlns:x="myns"></b> So, after this lengthy introduction the following questions: 1. Is there a way to make this work without having to contantly prefix all my xpath queries 2. Secondly, MS has come up with XDR, which is declared as follows: xmlns="x-schema:myschema.xdr" The problem is, that automatic validating happens in this case in tools such as XML spy. I cant find a way to declare that namespace inside an XSLT without having problems running the XLST because validation kicks in..... Anybody know some workarounds for these things? Grtz, Raimond XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: XSLT and Default namespaces, Evan Lenz | Thread | RE: XSLT and Default namespaces, Evan Lenz |
RE: XSLT and Default namespaces, Evan Lenz | Date | RE: <xsl:stylesheet xmlns:xsl=" ???, Evan Lenz |
Month |