Re: How to remove namespace declarations and prefixes?
For the same problem I'm using this pure XSL solution xsl:template match=* priority=-1 mode=copy xsl:element name={name()} xsl:copy-of select=@*/ xsl:apply-templates mode=copy/ /xsl:element /xsl:template xsl:template match=text() mode=copy xsl:value-of select=normalize-space(.)/ /xsl:template The weight on performance could be balanced by finer handling of nodes. - Original Message - From: Lai, Harry [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 01, 2002 4:54 PM Subject: RE: How to remove namespace declarations and prefixes? Hi Richard, I also had this same problem. I did some reading, and according to Michael Kay's XSLT Programmer's Reference: The xsl:exclude-result-prefixes and exclude-result-prefixes attributes apply only to namespace nodes copied from the stylesheet using literal result elements. They do not affect namespace nodes copied from the source document using xsl:copy or xsl:copy-of: there is no way of suppressing these. Unfortunately, since xslt's will often have a catch-all template matcher to copy elements it doesn't transform, this comes up quite a bit. So... what I ended up doing was extending the HTMLSerializer (or whatever serializer you're using for your pipelines), and overriding the startPrefixMapping and endPrefixMapping methods to do nothing, effectively removing all namespaces from my HTML. This also had the added benefit of having no performance penalties (and theoretically, a ever-so-slight speedup since we no longer process namespaces in our serializer). You could make this more general, and use the serializer's configuration to declare which namespaces you want to exclude, but excluding all worked well for us, especially since we were outputting HTML. Hope that helps! Harry - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to remove namespace declarations and prefixes?
Thank you for this solution. - Do you know if this influences the performance? - Is there a special reason why exclude-result-prefixes doesn't work or is it a bug? Regards, Reinhard -Original Message- From: Manos Batsis [mailto:[EMAIL PROTECTED]] Sent: Monday, July 01, 2002 12:45 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: How to remove namespace declarations and prefixes? Piece of cake. A stylesheet which does exactly that would 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=* !-- remove element prefix (if any) -- xsl:element name={local-name()} !-- process attributes -- xsl:for-each select=@* !-- remove attribute prefix (if any) -- xsl:attribute name={local-name()} xsl:value-of select=./ /xsl:attribute /xsl:for-each xsl:apply-templates/ /xsl:element /xsl:template /xsl:stylesheet However, adding another step in your pipeline may not be the best solution. You might want to modify your existing last stylesheet to remove prefixes using the local-name() function as above. Hope this helps, Manos - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to remove namespace declarations and prefixes?
From: Reinhard Poetz [mailto:[EMAIL PROTECTED]] Thank you for this solution. - Do you know if this influences the performance? Reinhard, *anything* influences performance. The professor at the course I follow, presented this issue very simply as In software design, you always give some to take some. - Is there a special reason why exclude-result-prefixes doesn't work or is it a bug? Are you using it correctly? For example, if you know your XSLT will *only* process either XSD or XHTML documents, you can do the same with ?xml version=1.0 encoding=UTF-8? xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:xs=http://www.w3.org/2001/XMLSchema; xmlns:xht=http://www.w3.org/1999/xhtml; exclude-result-prefixes=xs xht xsl:output method=xml version=1.0 encoding=UTF-8 indent=yes/ xsl:template match=*|@* xsl:copy xsl:apply-templates/ /xsl:copy /xsl:template /xsl:stylesheet Note that you have to declare ALL the namespaces you wish to filter out by associate them with a namespace prefix(duh); then put a space separated list of ALL prefixes as the value of the exclude-result-prefixes attribute. The only case this doesn't work is when you don't know the namespaces you may encounter. Cheers, Manos Regards, Reinhard -Original Message- From: Manos Batsis [mailto:[EMAIL PROTECTED]] Sent: Monday, July 01, 2002 12:45 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: How to remove namespace declarations and prefixes? Piece of cake. A stylesheet which does exactly that would 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=* !-- remove element prefix (if any) -- xsl:element name={local-name()} !-- process attributes -- xsl:for-each select=@* !-- remove attribute prefix (if any) -- xsl:attribute name={local-name()} xsl:value-of select=./ /xsl:attribute /xsl:for-each xsl:apply-templates/ /xsl:element /xsl:template /xsl:stylesheet However, adding another step in your pipeline may not be the best solution. You might want to modify your existing last stylesheet to remove prefixes using the local-name() function as above. Hope this helps, Manos - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to remove namespace declarations and prefixes?
-Original Message- From: Manos Batsis [mailto:[EMAIL PROTECTED]] Sent: Monday, July 01, 2002 1:21 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: How to remove namespace declarations and prefixes? - Do you know if this influences the performance? Reinhard, *anything* influences performance. The professor at the course I follow, presented this issue very simply as In software design, you always give some to take some. That's absoluty clear - may I have to pose the question more correctly: Is there a difference in performance - your solution compared to a working exclude-result-prefixes-attribute? - Is there a special reason why exclude-result-prefixes doesn't work or is it a bug? Are you using it correctly? For example, if you know your XSLT will *only* process either XSD or XHTML documents, you can do the same with ?xml version=1.0 encoding=UTF-8? xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:xs=http://www.w3.org/2001/XMLSchema; xmlns:xht=http://www.w3.org/1999/xhtml; exclude-result-prefixes=xs xht xsl:output method=xml version=1.0 encoding=UTF-8 indent=yes/ xsl:template match=*|@* xsl:copy xsl:apply-templates/ /xsl:copy /xsl:template /xsl:stylesheet Note that you have to declare ALL the namespaces you wish to filter out by associate them with a namespace prefix(duh); then put a space separated list of ALL prefixes as the value of the exclude-result-prefixes attribute. The only case this doesn't work is when you don't know the namespaces you may encounter. Did you try it with Cocoon? If yes, which version do you use? My stylesheet: xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:f=http://www.poetz.cc/forms; xmlns:l=http://www.poetz.cc/linking; xmlns:cinclude=http://apache.org/cocoon/include/1.0; xmlns:dc=http://purl.org/dc/elements/1.1/; xmlns:rss=http://purl.org/rss/1.0/; xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#; exclude-result-prefixes=f ... Regards, Reinhard - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to remove namespace declarations and prefixes?
From: Reinhard Poetz [mailto:[EMAIL PROTECTED]] Is there a difference in performance - your solution compared to a working exclude-result-prefixes-attribute? Depends on whether you want to add a new stylesheet or modify the existing one (if any). While on the second choice (using xsl:element with local-name() in all templates that handle elements and attributes) performance should not change notisably; essentially this and exclude-result-prefixes do the same thing. Did you try it with Cocoon? If yes, which version do you use? Nope I haven't. My stylesheet: xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:f=http://www.poetz.cc/forms; xmlns:l=http://www.poetz.cc/linking; xmlns:cinclude=http://apache.org/cocoon/include/1.0; xmlns:dc=http://purl.org/dc/elements/1.1/; xmlns:rss=http://purl.org/rss/1.0/; xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#; exclude-result-prefixes=f Yes, the above will only remove namespace prefixes bound to http://www.poetz.cc/forms To filter all prefixes out modify the exclude-result-prefixes attribute to exclude-result-prefixes=f l cinclude dc rss rdf Hth, Manos - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to remove namespace declarations and prefixes?
From: Manos Batsis [mailto:[EMAIL PROTECTED]] From: Reinhard Poetz [mailto:[EMAIL PROTECTED]] Is there a difference in performance - your solution compared to a working exclude-result-prefixes-attribute? Depends on whether you want to add a new stylesheet or modify the existing one (if any). While on the second choice (using xsl:element with local-name() in all templates that handle elements and attributes) performance should not change notisably; essentially this and exclude-result-prefixes do the same thing. Did you try it with Cocoon? If yes, which version do you use? Nope I haven't. It seems to me that this is a bug in cocoon. My stylesheet: xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:f=http://www.poetz.cc/forms; xmlns:l=http://www.poetz.cc/linking; xmlns:cinclude=http://apache.org/cocoon/include/1.0; xmlns:dc=http://purl.org/dc/elements/1.1/; xmlns:rss=http://purl.org/rss/1.0/; xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#; exclude-result-prefixes=f Yes, the above will only remove namespace prefixes bound to http://www.poetz.cc/forms To filter all prefixes out modify the exclude-result-prefixes attribute to ATM it doesn't remove the namespace. I'll report the bug to bugzilla. Thanks for your help. Reinhard - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How to remove namespace declarations and prefixes?
Hi Richard, I also had this same problem. I did some reading, and according to Michael Kay's XSLT Programmer's Reference: The xsl:exclude-result-prefixes and exclude-result-prefixes attributes apply only to namespace nodes copied from the stylesheet using literal result elements. They do not affect namespace nodes copied from the source document using xsl:copy or xsl:copy-of: there is no way of suppressing these. Unfortunately, since xslt's will often have a catch-all template matcher to copy elements it doesn't transform, this comes up quite a bit. So... what I ended up doing was extending the HTMLSerializer (or whatever serializer you're using for your pipelines), and overriding the startPrefixMapping and endPrefixMapping methods to do nothing, effectively removing all namespaces from my HTML. This also had the added benefit of having no performance penalties (and theoretically, a ever-so-slight speedup since we no longer process namespaces in our serializer). You could make this more general, and use the serializer's configuration to declare which namespaces you want to exclude, but excluding all worked well for us, especially since we were outputting HTML. Hope that helps! Harry -Original Message- From: Reinhard Poetz [mailto:[EMAIL PROTECTED]] Sent: Monday, July 01, 2002 7:53 AM To: [EMAIL PROTECTED] Subject: RE: How to remove namespace declarations and prefixes? From: Manos Batsis [mailto:[EMAIL PROTECTED]] From: Reinhard Poetz [mailto:[EMAIL PROTECTED]] Is there a difference in performance - your solution compared to a working exclude-result-prefixes-attribute? Depends on whether you want to add a new stylesheet or modify the existing one (if any). While on the second choice (using xsl:element with local-name() in all templates that handle elements and attributes) performance should not change notisably; essentially this and exclude-result-prefixes do the same thing. Did you try it with Cocoon? If yes, which version do you use? Nope I haven't. It seems to me that this is a bug in cocoon. My stylesheet: xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform; xmlns:f=http://www.poetz.cc/forms; xmlns:l=http://www.poetz.cc/linking; xmlns:cinclude=http://apache.org/cocoon/include/1.0; xmlns:dc=http://purl.org/dc/elements/1.1/; xmlns:rss=http://purl.org/rss/1.0/; xmlns:rdf=http://www.w3.org/1999/02/22-rdf-syntax-ns#; exclude-result-prefixes=f Yes, the above will only remove namespace prefixes bound to http://www.poetz.cc/forms To filter all prefixes out modify the exclude-result-prefixes attribute to ATM it doesn't remove the namespace. I'll report the bug to bugzilla. Thanks for your help. Reinhard - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]