XSL转换新行定界符  字符串中的问题

时间:2018-12-13 15:02:08

标签: xml string xslt delimiter

我在转换为CSV时遇到问题。与XSL转换中的$ RowDelim完全相同。如下所示,行分隔符为
。一切都很好,直到在某个字符串行的表中突然出现的表出现的那一刻,比起作为新行的反应,但这对我来说是错误的行为。您知道合适的方法吗?我尝试了很多不同的方法,有时可能是错误的,但这不起作用

当前XML树:

<Rowsets>
<Rowset>
    <Columns>
        <Column Description="id" MaxRange="1" MinRange="0" Name="id" SQLDataType="-5" SourceColumn="id"/>
        <Column Description="Note" MaxRange="1" MinRange="0" Name="Note" SQLDataType="-9" SourceColumn="Note"/>
    </Columns>
    <Row>
    <id>9</id>
    <Note>Normal string without enter in string look like this</Note>
    </Row>
    <Row>
    <id>9</id>
    <Note>
    String with enter look like this
    </Note>
    </Row>
</Rowset>

我知道我需要完全更改此部分:

<xsl:for-each select="Row">

其余代码

<xsl:value-of select="$RowDelim"/>
</xsl:for-each>

在完成XSL转换之后

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
<xsl:output method="text" media-type="text/csv" encoding="UTF-8"/>
<xsl:param name="RowDelim">
    <xsl:text>&#xA;</xsl:text>
</xsl:param>
<xsl:param name="FieldDelim">,</xsl:param>
<xsl:param name="StringDelim">"</xsl:param>
<xsl:param name="DateFormat">yyyy-MM-dd HH:mm:ss</xsl:param>

<xsl:template match="/">
    <xsl:for-each select="Rowsets">
        <xsl:call-template name="PrintFatalError"/>
        <xsl:for-each select="Rowset">
            <xsl:variable name="CurrentColumns" select="Columns"/>
            <xsl:for-each select="Columns">
                <xsl:for-each select="Column">
                    <xsl:value-of select="$StringDelim"/>
                    <xsl:value-of select="@Name"/>
                    <xsl:value-of select="$StringDelim"/>
                    <xsl:if test="not(position() = last())">
                        <xsl:value-of select="$FieldDelim"/>
                    </xsl:if>
                </xsl:for-each>
                <xsl:value-of select="$RowDelim"/>
            </xsl:for-each>
            <xsl:for-each select="Row">
                <xsl:for-each select="*">
                    <xsl:variable name="ColName">
                        <xsl:value-of select="name(.)"/>
                    </xsl:variable>
                    <xsl:variable name="ColType">
                        <xsl:value-of select="$CurrentColumns/Column[@Name=$ColName]/@SQLDataType"/>
                    </xsl:variable>
                    <xsl:choose>
                        <xsl:when test="$ColType= '2' or $ColType= '3' or $ColType= '4' or $ColType= '5' or $ColType= '6' or $ColType= '7' or $ColType= '8' or $ColType= '-7' or $ColType ='-5' or $ColType ='-3' or $ColType ='-4' or $ColType ='-2'">
                                <xsl:choose>
                                    <xsl:when test=". = 'NA'">
                                        <xsl:value-of select="''"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="."/>
                                    </xsl:otherwise>
                                </xsl:choose>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="$StringDelim"/>
                            <xsl:choose>
                                <xsl:when test="$ColType= '91' or $ColType= '92' or $ColType= '93'">
                                    <xsl:choose>
                                        <xsl:when test=". = 'TimeUnavailable'">
                                            <xsl:value-of select="''"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="java:com.sap.xmii.Illuminator.ext.ExtFunctions.dateFromXMLFormat(string(.),$DateFormat)"/>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="."/>
                                </xsl:otherwise>
                            </xsl:choose>
                            <xsl:value-of select="$StringDelim"/>
                        </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="not(position() = last())">
                        <xsl:value-of select="$FieldDelim"/>
                    </xsl:if>
                </xsl:for-each>
                <xsl:value-of select="$RowDelim"/>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:for-each>
</xsl:template>
<xsl:template name="PrintFatalError">
    <xsl:for-each select="FatalError">
        <xsl:text>Fatal Error - </xsl:text>
        <xsl:value-of select="."/>
        <xsl:value-of select="$RowDelim"/>
    </xsl:for-each>
</xsl:template>

提前谢谢

0 个答案:

没有答案