2

2 つの異なる強調の間の間隔の値に関して問題があります。以下の xslt の現在の出力はまだ問題ありませんが、2 つのタグの間にスペースがありません。変形についてよくわからないので教えてください。詳細な問題は以下で見ることができます。

入力 XML は次のとおりです。

<caption>
    <content>Box</content>
      <number>1</number>
      <description>
        <em type="bold">Some text with scientic name: </em>
    <em type="bolditalic">fhadinistis</em>
      </description>
</caption>

出力は次のとおりです。

<cap>
    <text>Box</text>
    <num>1</num>
    <content>
        <b>Some text with scientic name:</b><b>
            <i>fhadinistis</i>
        </b>
    </content>
</cap>

目的の出力は次のようになります:(太字の終了タグと開始タグの間にスペースがあることに注意してください)

<cap>
    <text>Box</text>
    <num>1</num>
    <content>
        <b>Some text with scientic name:</b> <b>
            <i>fhadinistis</i>
        </b>
    </content>
</cap>

私のXSLTは次のとおりです。

<xsl:template match="em">
    <xsl:choose>
        <xsl:when test="@type='bolditalic'">
            <b>
                <it>
                    <xsl:apply-templates/>
                </it>
            </b>
        </xsl:when>
        <xsl:when test="@type='boldunderline'">
            <b>
                <ul>
                    <xsl:apply-templates/>
                </ul>
            </b>
        </xsl:when>
        <xsl:when test="@type='italicunderline'">
            <it>
                <ul>
                    <xsl:apply-templates/>
                </ul>
            </it>
        </xsl:when>                 
    </xsl:choose>
</xsl:template>
4

2 に答える 2

1

テンプレートの先頭にこれを置くだけです:

    <xsl:if test="preceding-sibling::*[1][self::em]">
      <xsl:text> </xsl:text>
    </xsl:if>
于 2012-09-07T12:38:42.903 に答える
0

空白が必要な場合はいつでも、次を使用してみてください。

<xsl:text>#x20;</xsl:text>

<xsl:text> </xsl:text>

トリックを行う必要がありますが、コード内の空白スペースを見逃すのは簡単です。 #x20; を使用することをお勧めします。視認性のために。

xsl:choose 終了タグの後に配置できます。したがって、xsl:choose = Nothing で複数の黒いスペースが表示された場合でも、HTML は 1 つしか表示しません (デフォルトで)。

次のように実装します。

<xsl:template match="em">
    <xsl:choose>
        <xsl:when test="@type='bolditalic'">
            <b>
                <it>
                    <xsl:apply-templates/>
                </it>
            </b>
        </xsl:when>
        <xsl:when test="@type='boldunderline'">
            <b>
                <ul>
                    <xsl:apply-templates/>
                </ul>
            </b>
        </xsl:when>
        <xsl:when test="@type='italicunderline'">
            <it>
                <ul>
                    <xsl:apply-templates/>
                </ul>
            </it>
        </xsl:when>                 
    </xsl:choose>
    <xsl:text>#x20;</xsl:text>
</xsl:template>
于 2012-09-07T10:49:45.577 に答える