他の誰かのために問題を解決しようとして、代わりに私自身の奇妙な問題に遭遇しました。それは簡単だと確信していますが、答えは私にはわかりません!
私が持っているXML:
<xml>
<head>
<info>
<content>
<source attribute1="RSC1985s5c1" attribute2="6(17)">
data1
</source>
<cite/>
<case/>
(
<target attribute1="LRC1985s5c1" attribute2="6(17)1">
3e/191
</target>
)
</content>
<content>
<source attribute1="RSC1985s5c1" attribute2="6(17)">
data2
</source>
<cite/>
<case/>
(
<target attribute1="LRC1985s5c4" attribute2="6(17)1">
4e/54
</target>
)
</content>
</info>
</head>
</xml>
XSLTを使用して、2つのコンテンツ要素を組み合わせます。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="info">
<xsl:copy>
<xsl:element name="content">
<xsl:for-each select="content">
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:for-each>
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
これにより、次のものが作成されます。
<?xml version="1.0" encoding="utf-8"?><xml> //Just noticed here too!
<head>
<info><content> //Why no new line here?
<source attribute1="RSC1985s5c1" attribute2="6(17)">
data1
</source>
<cite />
<case />
(
<target attribute1="LRC1985s5c1" attribute2="6(17)1">
3e/191
</target>
)
<source attribute1="RSC1985s5c1" attribute2="6(17)">
data2
</source>
<cite />
<case />
(
<target attribute1="LRC1985s5c4" attribute2="6(17)1">
4e/54
</target>
)
</content></info> //And again here?
</head>
</xml>
コメントを使用して強調された問題は、要素間に新しい行がない理由を理解できないことです。
前もって感謝します。