XSLT preserve whitespaces

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mahendra dubey
    New Member
    • Aug 2009
    • 16

    XSLT preserve whitespaces

    Hi there
    I am using XSLT to process an XML file.I want to copy all whole XML and want to modify some attribute node.I using follwing code
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
         xmlns:db="http://tempuri.org/DatabaseXMLSchema.xsd">
      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="@* | node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:template>
      </xsl:stylesheet>
    but i lost the whitespaces in this case if I add the " xml:space='pres erve'" and use follwing
    <xsl:template match="@* | node()" xml:space="pres erve">
    then I got follwing error
    Attribute and namespace nodes cannot be added to the parent element after a text, comment, pi, or sub-element node has already been added.

    please help me how can I do that....
    Last edited by Frinavale; Jan 8 '10, 03:05 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Have you tried adding xml:space="pres erve" to the template before adding the child element?

    -Frinny

    Comment

    Working...