我想使用XSL刪除不需要的空間元素。需要刪除不需要的空間元素
XML我測試:
<Body>
<h1>abc</h1>
<h1>efg</h1>
<p>efgh</p>
<h1> </h1>
</Body>
XSL我使用:
<xsl:template match="Body">
<xsl:copy>
<xsl:for-each-group select="*" group-adjacent="boolean(self::h1)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<h1>
<xsl:apply-templates select="current-group()/node()"/>
</h1>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
輸出我得到:
<Body>
<h1>abcefg</h1>
<p>efgh</p>
<h1> </h1>
</Body>
輸出我想:
<Body>
<h1>abcefg</h1>
<p>efgh</p>
</Body>
我需要刪除具有空間值的元素。請指教。在此先感謝
我認爲你需要更詳細地解釋你的輸入可以看起來怎麼樣,並且導致你想要的,什麼是應該,如果發生最後一個'h1'元素是否爲空或僅填充空白,但包含一些數據?你想要一組新的'h1'元素嗎? –