「タグとテキスト」が混在する XML を 2 つの「純粋な」部分に分割する必要が<b>
あり<i>
ます<sup>
。o 「テキストのみ」(//text()
およびフォーマットタグ)を持つ他の部分。
入力例:
<root>
Nonono <i>nonon</i> <data1/> <b>nono</b>
<data2>nononono <i>no</i>nononon</data2>.
<data3>blablabla<data4/></data3>
</root>
出力例:
<root>
<myTags>
<data1/>
<data2>nononono <i>no</i>nononon</data2>
<data3>blablabla<data4/></data3>
</myTags>
<myText>
Nonono <i>nonon</i> <b>nono</b>
nononono <i>no</i>nononon . blablabla
</myText>
</root>
よりリアルな1入力で編集し、
Nonono <i>nonon</i> <data1/> <b>nono <data66/> </b>
出力する必要があります
<data1/><data66/>
このケースは、もう少し複雑な問題を表しています。どのレベルでも発生する可能性があります。
xsl:transform
私のXSLTのコアの下(それは機能しません!)、
<xsl:template match="/">
<root>
<myTags><xsl:call-template name="copyOnlyTags"/></myTags>
<myText><xsl:call-template name="copyOnlyTextAndFormat"/></myText>
</root>
</xsl:template>
<!-- LIB -->
<xsl:template name="copyOnlyTags">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="node()[not(self::text())]">
<xsl:choose>
<xsl:when test="count(*)=0"> <!-- terminal -->
<xsl:copy-of select="."/>
</xsl:when>
<xsl:otherwise> <!-- recurrence -->
<xsl:call-template name="copyOnlyTags"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="copyOnlyTextAndFormat">
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="self::text()">
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="name()='i' or name()='sup' or name()='sub' or name()='b'">
<xsl:copy-of select="."/><!-- suppose only text into -->
</xsl:when>
<xsl:otherwise> <!-- recurrence -->
<xsl:call-template name="copyOnlyTextAndFormat"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>