开发者

Retaining Line Feeds used in xml while transforming the xml using xsl

I am transforming an xml using an xsl.I get the xml from Oracle database.When i transform I am unable to see the data in the format it was actually stored.In a particular node, the line feeds used which are seen in the xml but when i transform I am unable t see the line feeds.All the c开发者_如何学Goontent in the particluar node is displayed in a line.

Can some one help me in how to include the line feeds which are already there in the xml???

Thanks Raghav


As suggested above, if you're using MSXML then check that it's configured to preserve whitespace.

Also check that the stylesheet doesn't use <xsl:strip-space>.

Also, if you are using XSLT 2.0 then whitespace is stripped by default for elements defined in a DTD or schema as having element-only content.

Also, it's possible of course that your stylesheet code is doing something with the whitespace text nodes other than copying them to the output.


XML and derivitives compress white space so to the parser, they don't matter. Some parsers however have the option to preserve white space. In MSXML, you set the DomDocument's preserveWhiteSpace property to true.


Try using this transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes"/>
 <xsl:preserve-space elements="*"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

In case the linebreaks are still not displayed, this means that the XML parser is stripping-off all whitespace-only text nodes. Read the documentation how to invoke the parser so that this default action is suppressed -- like as suggested in Deanna's answer for MSXML.

In case the result from the above transformation does contain the linebreaks, then you are doing something in the code you haven't shown to us, that causes these linebreaks not to be displayed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜