テキストノードと、 'i
'または ''または 'list
'のようないくつかの要素を 'p
'要素内にグループ化する方法をお勧めします。 div
は子供がp
にならないようにしてください。特定のタイプのテキストノードと隣接要素をグループ化する
XML:
<article>
<body>
<para>
<display><fig>Fig1</fig></display>
the text node1
</para>
<para>
<display><fig>Fig1</fig></display>
</para>
<para>
<display><fig>Fig1</fig></display>
the text node1 <i>h</i> ther <b>b</b> the text4
<display><tab>Table1</tab></display>
the text node2
<list><li>list1</li></list>
</para>
<para>The text node3</para>
</body>
</article>
XML(改行や空白表示目的のために、第2回XML下記の使用を実行すると):(改行なし)
<article><body><para><display><fig>Fig1</fig></display>the text node1</para><para><display><fig>Fig1</fig></display></para><para><display><fig>Fig1</fig></display>the text node1 <i>h</i> ther <b>b</b> the text4<display><tab>Table1</tab></display>the text node2<list><li>list1</li></list></para><para>The text node3</para></body></article>
XSLT :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
<xsl:template match="para">
<xsl:choose>
<xsl:when test="not(text())"><xsl:apply-templates/></xsl:when>
<xsl:when test="display and text() or *">
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="name()='display'"><div><xsl:apply-templates/></div></xsl:when>
<xsl:when test="name()='i' or name()='b'">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:when>
<xsl:when test="not(*)"><p><xsl:value-of select="."/></p></xsl:when><!--Here grouping required with adjacent elements 'i' or 'b' etc -->
<xsl:otherwise><p><xsl:apply-templates/></p></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<p><xsl:apply-templates/></p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
必要な結果は:
<article>
<body>
<div><fig>Fig1</fig></div><!--ensure div should not child to 'p'-->
<p>the text node1</p> <!--Text area including 'i' and 'b' to be within 'p' -->
<div><fig>Fig1</fig></div>
<div><fig>Fig1</fig></div>
<p>the text node1 <i>h</i> ther <b>b</b> the text4</p><!--Text area including 'i' and 'b' to be within 'p' -->
<div><tab>Table1</tab></div>
<p>the text node2<list><li>list1</li></list></p><!--text area includes 'list' element -->
<p>The text node3</p>
</body>
</article>
おかげさまで素晴らしい提案をいただき、ありがとうございました。 –