2
考慮到這個XML代碼:如何保持和逃避無與倫比的元素?
<root>
blah <foo>blah</foo> blah <bar>blah</bar> blah
</root>
而他相關的樣式表:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="foo">
<strong><xsl:apply-templates/></strong>
</xsl:template>
</xsl:stylesheet>
與XSLTProcessor中類(PHP)transofrmation後,這裏是輸出:
blah <strong>blah</strong> blah blah blah
但我而是想要這個輸出(樣式表中的未知元素被轉義):
blah <strong>blah</strong> blah <bar>blah</bar> blah
我建議僞代碼:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="foo">
<strong><xsl:apply-templates/></strong>
</xsl:template>
<xsl:template match="all elements other than foo (with their attributs :p)">
<xsl:copy-of select="node()" escape="yes"/>
</xsl:template>
</xsl:stylesheet>
我絕望了,所以如果你有保持和逃避那些無用的元素的任何解決方案,我會很高興!
以及感謝,它的工作原理!但它不是原始元素的真正轉義副本,更像是「重建」。例如,如果元素是' blah ',則輸出將是'> blah '。 –
Ayell