not adding new line in my XSLT

一曲冷凌霜 提交于 2019-12-12 19:00:29

问题


I am not certain why my xslt won't put a new line in my output... This is my xslt....

<?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"
>
  <xsl:output method="text" encoding="iso-8859-1"/>
  <xsl:variable name="newline"></xsl:variable>
  <xsl:template name="FairWarningTransform" match="/">    <!--@* | node()">-->

          <xsl:for-each select="//SelectFairWarningInformationResult">  

                <xsl:value-of select="ApplicationID"/>,<xsl:value-of select="USERID"/>
                &#10;
          </xsl:for-each>

        * Note.  This report outlines Fair warning entries into reported for the above time frame.

      </xsl:template>
</xsl:stylesheet>

Here is my output...

1,TEST1,test2,

I want it to look like...

1,TEST
1,test2,

Why isn't this character creating a newline


回答1:


XSLT's default behavior is to ignore any text nodes in the stylesheet that are entirely whitespace (this is true even if some of the whitespace is encoded as entities like &#10;), except for text inside <xsl:text>, which is preserved.

I suggest replacing these lines:

<xsl:value-of select="ApplicationID"/>,<xsl:value-of select="USERID"/>
&#10;

with this:

<xsl:value-of select="concat(ApplicationID, ',', USERID, '&#10;')"/>

That way the newline should be ensured to be included in the output.




回答2:


Try replacing

&#10;

with

<xsl:text>&#10;</xsl:text>

That helps XSLT distinguish it from other whitespace in your stylesheet that is part of the stylesheet formatting (not part of the desired output).




回答3:


Try using this as your newline instead of the escaped character:

<xsl:text>
</xsl:text>


来源:https://stackoverflow.com/questions/14588509/not-adding-new-line-in-my-xslt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!