私はこのxmlファイルを持っています:
<?xml version="1.0" encoding="iso-8859-1"?>
<doclist>
<text attribute="a">This is a <tag1>sentence</tag1> <tag1>with</tag1> a few
<tag1>words</tag1>.</text>
<-- many more text nodes with none, one or several '<tag1>' in it -->
</doclist>
そして、私はこの結果を得たい:
<?xml version="1.0" encoding="iso-8859-1"?>
<doclist>
<text attribute="a">This is a <tag1>sentence with</tag1> a few <tag1>words</tag1>.
</text>
<-- many more text nodes with none, one or several '<tag1>'s in it -->
</doclist>
私は正規表現でそれをやってみました:
<xsl:template match="text">
<text>
<xsl:apply-templates select="@*"/> <!-- templ. to copy attributes of text -->
<xsl:analyze-string select="."
regex="<tag1>(.+)<tag1><tag1>(.+)</tag1>">
<!-- also tried . instead of < -->
<xsl:matching-substring>
<xsl:for-each select=".">
<tag1>
<xsl:value-of-select="regex-group(1)">
<xsl:text> <xsl:text>
<xsl:value-of-select="regex-group(2)">
</tag1>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:for each select=".">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:non-matching-substring>
</xsl:analyze-string>
</text>
</xsl:template>
しかし、私の出力は次のようになります。
<?xml version="1.0" encoding="iso-8859-1"?>
<doclist>
<text attribute="a>This is a sentencewitha few words.
</text>
<-- many more text nodes with none, one or several '<tag1>'s in it -->
</doclist>
私の推測では、結果に s が表示されないため、一致するものが見つからないということ<tag1>
ですが、タグで囲まれた単語だけが空白を失う理由がわかりません...<tag1>
直接の隣人である s を正しく折りたたむにはどうすればよいですか?