2017-09-17 24 views
3

XSLT 3.0を使用してXMLファイルをHTMLに出力していますが、コンマやピリオドの前に空白を取り除くのに問題があります。以下は、私が抱えている正確な問題の例です:XMLにはHTMLで再現されている行/改行があります。通常は、ブラウザが空白を1つの空白に畳んでしまうため、これは問題ではありません。下の例ではコンマやピリオドの前に空白が残っています。XML - XSLTからHTMLへの変換 - 特定の行/改行を排除する

(XMLについての注:中世の原稿のテキストエンコーディングであり、その中にさまざまな要素があり、さまざまなレベルの他の要素にネストされているように見えることがあります)。

XML:

  <persName> 
       <choice> 
       <orig>ar. p<hi rend="sup">a</hi>der</orig> 
       <reg>Arnaldum Prader</reg> 
       </choice> 
      </persName> et socium eius hereticos et vidit ibi cum eis <persName> 
       <choice> 
       <orig>P. barrau</orig> 
       <reg>Poncium Barrau</reg> 
       </choice> 
      </persName>, <persName> 
       <choice> 
       <orig>Iordanetū del maſ</orig> 
       <reg>Iordanetum del Mas</reg> 
       </choice> 
      </persName>, <persName> 
       <choice> 
       <orig>Iordanū de quiders</orig> 
       <reg>Iordanum de Quiders</reg> 
       </choice> 
      </persName> et <persName> 
       <choice> 
       <orig>W. Vitał</orig> 
       <reg>Willelmum Vitalis</reg> 
       </choice> 
      </persName> predictum et <persName> 
       <choice> 
       <orig>ux̄ dc̄ī W. Vitał</orig> 
       <reg>uxor dicti Willelmi Vitalis</reg> 
       </choice> 
      </persName>. 

XMLテンプレート:

<!-- format super/sub scripts --> 
<xsl:template match="tei:hi" name="template_supersub"> 
    <xsl:choose> 
     <xsl:when test="@rend ='sup'"><sup class="subsup"><xsl:apply-templates/></sup></xsl:when> 
     <xsl:when test="@rend ='sub'"><sub class="subsup"><xsl:apply-templates/></sub></xsl:when> 
    </xsl:choose> 
</xsl:template> 

<!-- parse persName into <spans> --> 
<xsl:template match="tei:persName/tei:choice/tei:reg"> 
    <span class="interpretive"><xsl:apply-templates/></span> 
</xsl:template> 

<xsl:template match="tei:persName/tei:choice/tei:orig"> 
    <span class="diplomatic"><xsl:apply-templates/></span> 
</xsl:template> 

現在のHTML出力:

 <span class="diplomatic">ar. p<sup class="subsup">a</sup>der</span> 
    <span class="interpretive">Arnaldum Prader</span> 

     et socium eius hereticos et vidit ibi cum eis 

    <span class="diplomatic">P. barrau</span> 
    <span class="interpretive">Poncium Barrau</span> 

    , 

    <span class="diplomatic">Iordanetū del maſ</span> 
    <span class="interpretive">Iordanetum del Mas</span> 

    , 

    <span class="diplomatic">Iordanū de quiders</span> 
    <span class="interpretive">Iordanum de Quiders</span> 

     et 

    <span class="diplomatic">W. Vitał</span> 
    <span class="interpretive">Willelmum Vitalis</span> 

     predictum et 

    <span class="diplomatic">ux̄ dc̄ī W. Vitał</span> 
    <span class="interpretive">uxor dicti Willelmi Vitalis</span> 

    . 

決勝、問題のある出力:

Arnaldum Praderは、Poncium Barrau、Iordanetum del Mas、Iordanum de Quiders et Willelmumと共同研究しています。

strip-space、replace()、translate()のさまざまな組み合わせがこの問題を対象としていません。彼らは通常、要素間にすべての空白を崩壊させます。

コンマやピリオドの前にスペースを入れないでください。カンマやピリオドの後にスペースを入れてください。しかし、私は、これに対処するためのメカニズムは見つけられません。ありがとう。

理想のHTML出力:

<span class="diplomatic">ar. p<sup class="subsup">a</sup>der</span> 
<span class="interpretive">Arnaldum Prader</span> et socium eius 
hereticos et vidit ibi cum eis <span class="diplomatic">P. 
barrau</span><span class="interpretive">Poncium Barrau</span>, <span 
class="diplomatic">Iordanetū del maſ</span><span 
class="interpretive">Iordanetum del Mas</span>, <span 
class="diplomatic">Iordanū de quiders</span><span 
class="interpretive">Iordanum de Quiders</span> et <span 
class="diplomatic">W. Vitał</span><span class="interpretive">Willelmum 
Vitalis</span> predictum et <span class="diplomatic">ux̄ dc̄ī W. 
Vitał</span><span class="interpretive">uxor dicti Willelmi 
Vitalis</span>. 
+1

スタイルシートに ''を追加すると問題は解決しますか? –

+0

@Tim C - 1つの問題を解決し、他の問題を紹介します。カンマとピリオドの前のスペースの問題は解決されますが、スペースが必要な要素間のスペースも崩壊します。 – idjet

+0

質問を編集して実際のhtml出力を表示することは可能でしょうか?ありがとうございました! –

答えて

0

本当に長い複雑なポストを避けるために、自分の質問への応答を投稿。このXSLに

<!-- parse persName into <spans> --> 
<xsl:template match="tei:persName/tei:choice/tei:reg"> 
    <span class="interpretive"><xsl:apply-templates/></span> 
</xsl:template> 

<xsl:template match="tei:persName/tei:choice/tei:orig"> 
    <span class="diplomatic"><xsl:apply-templates/></span> 
</xsl:template> 

私はこのXSL調整

<!-- parse persName into <spans> --> 
<xsl:template match="tei:persName"> 
<span class="interpretive"><xsl:apply-templates select="tei:choice/tei:reg"/></span><span class="diplomatic"><xsl:apply-templates select="tei:choice/tei:orig"/></span> 
</xsl:template> 

を、必要に応じて、今では正確にHTMLをエクスポートします。 XSLファイルのその他の調整はありません。なぜこれが違いになるのか分かりませんが、それは大きな違いです。

新しいHTML:あなたは「これは違いを作る理由を理解していない」と書いて、あなた自身の投稿にあなたの答えで

<span class="interpretive">Arnaldum Prader</span><span 
class="diplomatic">ar. p<sup class="subsup">a</sup>der</span> et 
socium eius hereticos et vidit ibi cum eis <span 
class="interpretive">Poncium Barrau</span><span class="diplomatic">P. 
barrau</span>, <span class="interpretive">Iordanetum del Mas</span> 
<span class="diplomatic">Iordanetū<span class="line_num diplomatic"> 
<span class="interpretive"> </span>del maſ</span>, <span 
class="interpretive">Iordanum de Quiders</span><span 
class="diplomatic">Iordanū de quiders</span> et <span 
class="interpretive">Willelmum Vitalis</span><span 
class="diplomatic">W. Vitał</span> predictum et <span 
class="interpretive">uxor dicti Willelmi Vitalis</span><span 
class="diplomatic">ux̄ dc̄ī W. Vitał</span>. 
1

。私は助けてみましょう:choicepersName[choice]の中のすべての空白の子ノードが、例えば<の選択>と<orig>の間の文字通りのスペースを避ける必要があります。これらはコンテンツの一部ではなく、TEI構造のみであり、無視する必要があります。これは、TEIで働くときに頻繁に、また異なるレベルで繰り返される問題です。

これらのテンプレートは、この問題をより理解しやすい方法でカバーする方法を示します。すべてのテンプレート(テキストノードを含む)を適用する代わりに、出力に必要な要素のみを明示的に名前を付けることができます。

<xsl:template match="tei:choice"> 
    <xsl:apply-templates select="tei:reg"/> 
    <xsl:apply-templates select="tei:orig"/> 
</xsl:template> 

<xsl:template match="tei:persName[tei:choice]"> 
    <xsl:apply-templates select="tei:choice"/> 
</xsl:template> 

最終的な注意:スキーマに注意してください。 persNameに、choice以外の空白以外のテキストが含まれていることが許可されている場合(通常はそうです)、これを別の方法で扱う必要があります。ここでの解決方法は、choiceが常にregorigである場合にのみpersNameが含まれている場合にのみ機能します。

+0

でこれを読んでください。本当にありがとうございました。 – idjet

+0

あなたは大歓迎です! –

関連する問題