Trouble Preserving White Space

Jeff King
  • Jeff King
    Jeff King

    We are running an XSLT stylesheet on an XML file (Docbook) and are
    transforming it into WordprocessingML. We would like to preserve the white
    space, including extra spaces and carriage returns. Using the <xsl:preserve- space=""> element or the xml:space="preserve" attribute seems to have no effect,
    the spaces get stripped. Does anyone have any suggestions for dealing with
    Thank you.

  • Michael Kay
    Michael Kay

    xsl:preserve-space is the default, so I wouldn't expect this to make a

    Need to find out when and why the whitespace is disappearing. You haven't said
    anything about your environment. If you're on .NET and using the Microsoft XML
    parser, for example, it strips whitespace by default. In other environments
    insignificant whitespace is stripped if you are validating against a schema or
    a DTD. So we need more detail of what you are doing.

    Confirm whether the whitespace is getting as far as your stylesheet by running
    a transform that just does xsl:copy-of select="/". If that contains the
    whitespace, the problem is in your XSLT code. If it doesn't, the problem is in
    the XML parser setup.

  • Jeff King
    Jeff King

    Thank you for your quick response. Your suggestions for researching this were
    very helpful. We found the place in the stylesheet that was removing the
    spaces and tabs. The carriage returns are being removed by Word itself at the
    time we are saving it. Thanks again.