not adding new line in my XSLT

2019-07-21 12:17发布

问题:

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>


标签: xslt newline