0

私はこのようなxmlを持っています、

<Parent> Running text with marked up entities like 
  <Child>Entity1</Child> 
 and, text in the middle too, and
  <Child> Entity2 </Child>
</Parent>

親をレンダリングするときに改行とインデントを保持する必要がありますが、すべての子タグにも強調表示テンプレートを適用する必要があります。

ここで、親タグの内容を変数に取り込んで XSL で文字列処理を行うと、基になる xml 構造が失われ、強調表示テンプレートを子に適用できなくなります。

一方、親タグに含まれるテキストの改行とインデントを保持する他の方法は考えられません。

何か案は?

4

2 に答える 2

0

コードを表示していないため、何を間違えたかを判断するのはかなり困難ですが、説明されている症状の原因となる一般的な間違いは、次のように書くことです。

<xsl:variable name="x">
  <xsl:value-of select="some/node/path"/>
</xsl:variable>

あなたが書くべきだったとき

<xsl:variable name="x" select="some/node/path"/>

将来的には、コードを表示しないとコードが機能しないと言わないでください。

于 2011-04-13T19:20:13.347 に答える
0

このスタイルシート:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:preserve-space elements="*"/>
    <xsl:template match="Parent">
        <div>
            <xsl:apply-templates mode="preserve"/>
        </div>
    </xsl:template>
    <xsl:template match="text()" mode="preserve" name="split">
        <xsl:param name="pString" select="."/>
        <xsl:choose>
            <xsl:when test="contains($pString,'&#xA;')">
                <xsl:value-of select="substring-before($pString,'&#xA;')"/>
                <br/>
                <xsl:call-template name="split">
                    <xsl:with-param name="pString"
                     select="substring-after($pString,'&#xA;')"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$pString"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="Child" mode="preserve">
        <b>
            <xsl:apply-templates mode="preserve"/>
        </b>
    </xsl:template>
</xsl:stylesheet>

出力:

<div> Running text with marked up entities like<br/> <b>Entity1</b><br/> and, text in the middle too, and<br/> <b> Entity2 </b><br/></div>

レンダリング:


Entity1の ようなマークアップされたエンティティを含む実行中のテキストと
、中央のテキスト、および
Entity2


編集:空白のみのテキストノードを保持するより良い例。

于 2011-04-13T14:57:34.183 に答える