Help needed with XSLT

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?

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?

Thanks for the response. 1. Is there a particular XSL list you refer to? 2. In our application, we process hundreds of thousands of SVG images. Individual teams are responsible for providing an stylesheet that produces a 'cleaned' SVG; this is for space savings (we're talking on the order of 100 GB here, so a 50% reduction is a big deal). To know that their stylesheets have not 'broken' the SVG, the publishing process has an in-bult check for well-formedness, and validates against the SVG spec; those attributes do not prevent rendering, but they do prevent validation. Which means we can not check that other errors are not present. 3. We use Saxon-EE, as that is what oXygen uses, and we wanted to deploy with the same. So we've licensed Saxon. 4. Ya, I originally had the SVG as an element, but that caused me some other grief I can't remember. 5. I'm not an XSLT programmer, so this is not surprising, even though it is unfortunate. All I can do is try something, see if it has a positive result (makes my output more like I want it), and go from there. I'll study your changes, and try to incorporate them. Thanks! On Thu, Jun 23, 2011 at 2:16 PM, Syd Bauman <Syd_Bauman@brown.edu> wrote:
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?
oXygen-user mailing list oXygen-user@oxygenxml.com http://www.oxygenxml.com/mailman/listinfo/oxygen-user

1. Is there a particular XSL list you refer to?
Oh, indeed. See http://www.mulberrytech.com/xsl/xsl-list/. *The* XSL list, IMHO.
2. ... we process hundreds of thousands of SVG images. ... those attributes do not prevent rendering, but they do prevent validation.
Oh. Wow. Well, I guess it is quite important, then. But I thought you said you were using RNG? I'm guessing the final validation is against a DTD, or else they wouldn't be a problem. (Why? Because in the XDM those aren't attributes, they're namespace declarations. DTDs don't know about modern XML, so they look like attributes to a DTD.)
5. I'm not an XSLT programmer, so this is not surprising, even though it is unfortunate. All I can do is try something, see if it has a positive result (makes my output more like I want it), and go from there. I'll study your changes, and try to incorporate them.
Oh dear; please realize no insults intended. Trial-and-error is a tried and true method, one on which I certainly rely heavily. I was just in a bit of a rush, trying to get mail off to you before I had to go play soccer dad, and up to my eyeballs in projects, here. (One of which is getting ready for an upcoming workshop on XSLT for digital humanists, which is why XSLT programming style is on my mind :-)

Syd Bauman wrote: Hi,
1) This is probably more appropriate for the XSL-list than here.
Might not be the case actually. The fact that the graph namespace is asked to be excluded from serialization but is not actually, is maybe because the serialization ignores it. It could be a lot of reasons, really, but I think the serializer in oXygen which serializes to the GUI, with syntax-highlighting, is ignoring this serialization param. Timothy, do you observe that result directly in oXygen? What if you run the transform from within the command line, using Saxon directly? Just an idea... Regards, -- Florent Georges http://fgeorges.org/

On Fri, June 24, 2011 10:42 am, Florent Georges wrote:
Syd Bauman wrote:
1) This is probably more appropriate for the XSL-list than here.
Might not be the case actually. The fact that the graph
Definitely the case.
namespace is asked to be excluded from serialization but is not actually, is maybe because the serialization ignores it. It could be a lot of reasons, really, but I think the serializer in oXygen which serializes to the GUI, with syntax-highlighting, is ignoring this serialization param.
Timothy, do you observe that result directly in oXygen? What if you run the transform from within the command line, using Saxon directly? Just an idea...
'exclude-result-prefixes' is for excluding namespace declarations from literal result elements created by the stylesheet [1]. It's not going to make them disappear from elements that were added to the result by using xsl:copy. Regards, Tony Graham tgraham@mentea.net Consultant http://www.mentea.net Mentea 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- XML, XSL FO and XSLT consulting, training and programming [1] http://www.w3.org/TR/xslt20/#lre-namespaces

Tony Graham wrote: Hi,
'exclude-result-prefixes' is for excluding namespace declarations from literal result elements created by the stylesheet
Oops, I was too quick in responding, thanks for the correction and sorry for the noise, -- Florent Georges http://fgeorges.org/
participants (4)
-
Florent Georges
-
Reaves, Timothy
-
Syd Bauman
-
Tony Graham