
1) This is probably more appropriate for the XSL-list than here. You would likely find that if you followed the (stringent) posting guidelines for that list, you'd have your answer before you post. At least, I usually do :-) 2) Out of curiosity, why do you care? There is really no harm done having extra namespace declarations on the SVG root element, is there? (I agree it is ugly as sin, and often run the output of my transforms through an editing step to strip 'em off: $ saxon style.xslt in.xml | perl -pe 's, xmlns:duck="http://www.example.org/ns/",,;' > out.xml 3) What processor are you using? 4) I can take a crack at reducing the namespace declarations on the output <svg> node by making it an explicit literal result element instead of using <copy>. The i prefix is still there, though. (I presume because it's tested for in the code). See below. 5) This strikes me as very non-XSLT-like code, and very inefficient. (You are testing every attribute, comment, or processing instruction to see if it is in the sequence of every metadata, switch, etc.) Here is a rewrite that takes care of all but 1 extra namespace, and I think does the same job in a clearer and more efficient manner: --------- <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" xmlns:graph="http://ns.adobe.com/Graphs/1.0/" xmlns:x="http://ns.adobe.com/Extensibility/1.0/" exclude-result-prefixes="xs xd a x graph" xpath-default-namespace="http://www.w3.org/2000/svg" version="2.0"> <xsl:template match="/"> <svg xmlns="http://www.w3.org/2000/svg"> <xsl:apply-templates select="svg/*"/> </svg> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="comment()|processing-instruction()|text()"> <xsl:copy/> </xsl:template> <xsl:template match="@*"> <xsl:if test="namespace-uri() ne 'http://ns.adobe.com/AdobeIllustrator/10.0/'"> <xsl:copy/> </xsl:if> </xsl:template> <xsl:template match="i:pgf | metadata | foreignObject"/> <xsl:template match="switch"> <xsl:apply-templates select="node()"/> </xsl:template> </xsl:stylesheet> --------- HTH.
I'm applying a transform to SVG documents, to make them validate against the SVG RNG schema. I have everything working EXCEPT the name spaces on the SVG element itself. These SVG documents where edited in Adobe Illistrator, and the original SVG element is:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:a=" http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" xmlns:graph=" http://ns.adobe.com/Graphs/1.0/" xmlns:i=" http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:x=" http://ns.adobe.com/Extensibility/1.0/" xmlns:xlink=" http://www.w3.org/1999/xlink">
and what I want is:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink=" http://www.w3.org/1999/xlink">
The stylesheet starts: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" xmlns:graph="http://ns.adobe.com/Graphs/1.0/" xmlns:x="http://ns.adobe.com/Extensibility/1.0/" exclude-result-prefixes="xs xd a x graph" xpath-default-namespace="http://www.w3.org/2000/svg" version="2.0">
My understanding is that 'exclude-result-prefixes="xs xd a x graph"' should not copy over the namespaces identified, but a, x, and graph are still there in the output. My main template is below, and it keeps the namespace & extensions off of the child elements of SVG, just not the SVG node itself.
<xsl:template match="@*|node()"> <xsl:choose> <xsl:when test=". = //i:pgf"/> <!-- This is the BLOB --> <xsl:when test=". = //@i:*" /> <!-- These three are all of the Adobe extensions --> <xsl:when test=". = //metadata"/> <xsl:when test=". = //foreignObject"/> <xsl:when test=". = //switch"> <!-- We do not want the switch elements, just their text nodes. --> <xsl:apply-templates select="node()"/> </xsl:when> <xsl:otherwise> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template>
Any ideas?