2

改行を<Break/>タグに置き換える XSLT がいくつかありますが、複数の連続した改行がない限り問題なく動作します。indent="yes"それが問題を引き起こしていると思います。一部のノードで無効にできますか?

基本的に、混合コンテンツ (テキストと要素) を持つノードには、改行を含めることはできません。

入力 xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Account xmlns="http://example.com/account">
    <Owner>
        <ID>012345789</ID>
        <Name>Peter Johnson</Name>
    </Owner>
    <Notes>
        <NoteID>012345789</NoteID>
        <Text>This is the description:
Line 1
Line 2
Line 3

Line 4, after double linebreak
Line 5</Text>
    </Notes>
</Account>

XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://example.com/account" version="1.0">

<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes"/>

<xsl:template name="replace_sab">
    <!-- with string s, replace substring a by string b -->
    <!-- s, a and b are parameters determined upon calling  -->
    <xsl:param name="s" />
    <xsl:param name="a" />
    <xsl:param name="b" />
    <xsl:choose>
        <xsl:when test="contains($s,$a)">
            <xsl:value-of select="substring-before($s,$a)" />
            <xsl:copy-of select="$b" />
            <xsl:call-template name="replace_sab">
                <xsl:with-param name="s" select="substring-after($s,$a)" />
                <xsl:with-param name="a" select="$a" />
                <xsl:with-param name="b" select="$b" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$s" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

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

<xsl:template match="text()[not(normalize-space())]"/>

  <xsl:template match="text()[boolean(normalize-space())]">
    <xsl:call-template name="replace_sab">
        <xsl:with-param name="s" select="." />
        <xsl:with-param name="a" select="'&#xA;'" />
        <xsl:with-param name="b"><Break/></xsl:with-param>
    </xsl:call-template>
  </xsl:template>
</xsl:stylesheet>

私が得る出力:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Account xmlns="http://example.com/account">
    <Owner>
        <ID>012345789</ID>
        <Name>Peter Johnson</Name>
    </Owner>
    <Notes>
        <NoteID>012345789</NoteID>
        <Text>This is the description:<Break/>Line 1<Break/>Line 2<Break/>Line 3<Break/>
            <Break/>Line 4, after double linebreak<Break/>Line 5</Text>
    </Notes>
</Account>

私が望む出力:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Account xmlns="http://example.com/account">
    <Owner>
        <ID>012345789</ID>
        <Name>Peter Johnson</Name>
    </Owner>
    <Notes>
        <NoteID>012345789</NoteID>
        <Text>This is the description:<Break/>Line 1<Break/>Line 2<Break/>Line 3<Break/><Break/>Line 4, after double linebreak<Break/>Line 5</Text>
    </Notes>
</Account>

Tibco BusinessWorks プロセスで「TIBCO XSLT 1.0」XSLT エンジンを使用しています。

4

1 に答える 1

2

これを行う標準的な方法はありません。

Saxon を使用している場合は、saxon:suppress-indentation 出力パラメーターを使用できます。これは、XSLT 3.0 の標準オプションになります。

Tibco XSLT エンジンを使い続けたとしても、Saxon シリアライザーを処理パイプラインに挿入する方法を見つけることができるかもしれません。

于 2012-11-28T12:05:49.357 に答える