469,306 Members | 2,549 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

can't get rid of xmlns attribute

Dormilich
8,651 Expert Mod 8TB
Hi,

I have some problems removing the xmlns attributes from a transformed xml file. I can't completely remove them (so it would validate).

the problematic elements are <div> or the elements pasted by <xsl:copy-of>

if I have no default NS in the XSL file I get the namespace attribute attached to the copied elements (the one from the "plan" prefix because that's default NS of the XML, all prefixed NS are removed).

if I have a default NS in the XSL file, the copied elements are free of NS, but the NS is now attached to the <div> element (because it's the top level element in the result XML).

so, how do I need to change my copy construct to get all elements without NS?

alternatively I have to add a preg_replace() function to my script, if this is not possible with XSL......

the xsl file (the important part):
Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet version="1.0"
  2.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.     xmlns:plan="urn:kbl.plan:current-and-bygone-playlists" // default NS of the XML file
  4.     exclude-result-prefixes="xsl plan">
  5.  
  6. [...]
  7.  
  8. <xsl:template match="/">
  9.   <xsl:element name="div">  // either I have xmlns="..." here ...
  10.     <xsl:attribute name="class">
  11.       <xsl:text>mitte inhalt</xsl:text>
  12.     </xsl:attribute>
  13. [...]
  14.     <xsl:for-each select="$basis/child::plan:thema">
  15.       <xsl:call-template name="themen" />
  16.     </xsl:for-each>
  17.   </xsl:element>
  18. </xsl:template>
  19.  
  20. <xsl:template name="themen">
  21.   <xsl:call-template name="balken" />
  22.   <xsl:for-each select="plan:termin">
  23.     <xsl:call-template name="termine" />
  24.   </xsl:for-each>
  25.   <xsl:if test="plan:xhtml">
  26.     <xsl:copy-of select="plan:xhtml/*" /> // ... or here
  27.   </xsl:if>
  28. </xsl:template>
  29.  
Dec 27 '08 #1
6 5241
jkmyoung
2,057 Expert 2GB
Have you tried using a seperate copy template?
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="copy">
  2.   <xsl:element name="local-name()">
  3.     <xsl:copy-of select="@*"/>
  4.     <xsl:for-each select="*">
  5.       <xsl:call-template name="copy"/>
  6.     </xsl:for-each>
  7.   </xsl:element>
  8. </xsl:template>
  9.  
  10. Change 
  11. <xsl:copy-of select="plan:xhtml/*" />
  12. with
  13. <xsl:for-each select="plan:xhtml/*">
  14.   <xsl:call-template name="copy"/>
  15. </xsl:for-each>
  16.  
Jan 5 '09 #2
Dormilich
8,651 Expert Mod 8TB
@jkmyoung
admittedly you are much better with such copy problems than I am. I'll try it.

regards
Jan 5 '09 #3
Dormilich
8,651 Expert Mod 8TB
tried the template but I got a problem. the XSLT returns with an error (i.e. the XSLTProcessor::transformToXml() method returns false. I could narrow down the problem to the following:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="copy">
  2. // if I use this line I get the error
  3.   <xsl:element name="local-name()">
  4.     <xsl:copy-of select="@*"/>
  5.     <xsl:for-each select="*">
  6.       <xsl:call-template name="copy"/>
  7.     </xsl:for-each>
  8.   </xsl:element>
  9. </xsl:template>
I have no idea, why it does so.....
Jan 8 '09 #4
Dormilich
8,651 Expert Mod 8TB
finally solved the problem, looked like the name attribute doesn't accept every input. nevertheless, thank you jkmyoung!
Expand|Select|Wrap|Line Numbers
  1. <xsl:template name="copy">
  2.   <xsl:element name="{local-name()}">
  3.     <xsl:copy-of select="@*"/>
  4.     <xsl:value-of select="text()"/>
  5.     <xsl:for-each select="plan:*">
  6.       <xsl:call-template name="copy"/>
  7.     </xsl:for-each>
  8.   </xsl:element>
  9. </xsl:template>
Jan 8 '09 #5
jkmyoung
2,057 Expert 2GB
Sorry, forgot that attribute was a string, not an xpath. But you figured out the braces so it's ok.
Jan 8 '09 #6
Dormilich
8,651 Expert Mod 8TB
@jkmyoung
it was rather a lucky guess....
Jan 8 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Julio | last post: by
reply views Thread by chris.stromberger | last post: by
reply views Thread by Ewan Fairweather | last post: by
3 posts views Thread by =?Utf-8?B?R3JlZw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.