私はこのような単純なXMLをいくつか持っています...
<?xml version="1.0" encoding="UTF-8"?>
<root>
<sentence>
<word1>The</word1>
<word2>cat</word2>
<word3>sat</word3>
<word4>on</word4>
<word5>the</word5>
<word6>mat</word6>
</sentence>
<sentence>
<word1>The</word1>
<word2>quick</word2>
<word3>brown</word3>
<word4>fox</word4>
<word5>did</word5>
<word6>nothing</word6>
</sentence>
</root>
私ができるようにしたいのは、これを XSLT で処理して、次のような文を作成することです。 The~cat~sat~on~the~mat
(これは私が最終的にできるようにしたいことの単純化された例です。これは今のところ障害にすぎません)。
私の XSLT は次のようになります。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" />
<xsl:template match="text()[not(string-length(normalize-space()))]"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:text>
</xsl:text>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="/root/sentence">
<xsl:apply-templates />
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="word1">
<xsl:value-of select="text()" />
~
</xsl:template>
<xsl:template match="word2">
<xsl:value-of select="text()" />
~
</xsl:template>
<xsl:template match="word3">
<xsl:value-of select="text()" />
~
</xsl:template>
<xsl:template match="word4">
<xsl:value-of select="text()" />
~
</xsl:template>
<xsl:template match="word5">
<xsl:value-of select="text()" />
~
</xsl:template>
<xsl:template match="word6">
<xsl:value-of select="text()" />
~
</xsl:template>
</xsl:stylesheet>
XML に対してスタイルシートを実行すると、次のように、各単語が 1 行に表示され、次の行にチルダが表示されます。
<?xml version="1.0" encoding="UTF-8"?>
The
~
cat
~
sat
~
on
~
the
~
mat
~
The
~
quick
~
brown
~
fox
~
did
~
nothing
~
ティルダを削除すると、
Thecatsatonthemat
それから私には見えます(そして私はこのXSLTのことは初めてです)、の新しい行にチルダを含めると、新しい行が強制されます。
では、テンプレートからの出力をすべて 1 行にまとめるにはどうすればよいでしょうか。(私の最後の要件は、要素にさらに書式を設定し、要素を埋めるためのスペースを追加することです。これについては後で説明します)。
よろしくお願いします