Domanda

I have an xslt file which creates a simple flat file. The output file originally had a .txt extension, but now it needs to be a .dat extension. Everything was perfect, but once I changed the extension, the .dat file does not interpret the new line character correctly.

Here is my XSLT file:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions">

<xsl:output method="text" encoding="utf-8"  />
<xsl:strip-space  elements="*"/>

<!-- Output File type is .DAT => This extension uses a different value for new line characters -->
<xsl:variable name="newline" select="'&#10;'"/>
<!-- <xsl:variable name='newline'><xsl:text> -->
<!-- </xsl:text></xsl:variable> -->
<xsl:variable name="tab" select="'&#x09;'" />
<xsl:variable name="comma" select="'&#x2C;'" />
<xsl:variable name="padding" select="'                              '" /> <!-- 30 spaces for padding -->
<xsl:variable name="zeroes">00000000000</xsl:variable>
<xsl:variable name="sevzeroes">0000000</xsl:variable>

    <xsl:template match="/">
        <xsl:for-each select="/ROOT/Payment">

                <!-- Filler -->
                <xsl:value-of select="substring(concat($padding, $padding), 1, 31)"/>
                <!-- Check Amount -->
                <xsl:value-of select="substring(concat($zeroes, amount), (1 + string-length(amount)), (11 + string-length(amount)))"/>

                <!-- Credit Indicator -->
                <xsl:choose>
                    <xsl:when test="is_void = 0">
                        <xsl:text> </xsl:text>
                    </xsl:when>
                    <xsl:when test="is_void = 1">
                        <xsl:text>C</xsl:text>
                    </xsl:when>
                </xsl:choose>

                <!-- Filler -->
                <xsl:text> </xsl:text>
                <!-- Check Number -->
                <xsl:value-of select="substring(concat($sevzeroes, check_number), (1 + string-length(check_number)), (7 + string-length(check_number)))"/>

                <!-- Check Date -->
                <!-- Incoming Date Format 2014-03-11-07:00 -->
                <xsl:variable name="firstDate" select="last_printed" />
                <xsl:variable name="day" select="substring-before(substring-after(substring-after($firstDate, '-'), '-'), '-')"/>
                <xsl:variable name="month" select="substring-before(substring-after($firstDate, '-'), '-')"/>
                <xsl:variable name="year" select="substring-before($firstDate, '-')"/>

                <xsl:value-of select="substring(concat($month, $day, $year, $padding), 1, 8)"/>

                <!-- TYPE -->
                <xsl:text>S</xsl:text>
                <!-- Filler -->
                <xsl:value-of select="substring(concat($padding, $padding), 1, 31)"/>

                <xsl:value-of select="$newline"/>
<!--            </xsl:if> -->
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

I tried setting the value of the newline variable to &#x0A, &#x0D0A, &#10 and even using <xsl:variable name='newline'><xsl:text> </xsl:text></xsl:variable>

Am I missing something here? Thanks

È stato utile?

Soluzione

I found that the answer was to modify the value of the newline variable using both x0D and x0A.

Here is the variable newline:

<xsl:variable name="newline" select="'&#x0D;&#x0A;'"/>

Hopefully this helps others having the same problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top