Я пытаюсь удалить заголовок тега с помощью XSLT. Но это не удаление. Можно ли рекомендовать решение для удаления заголовка якоря.
XML-файл
<?xml version="1.0" encoding="utf-8"?>
<RichText xmlns="uuid:e25b1476-ce87-4a67-a22b-b82a752810e0">
<Content>
<a xmlns="http://www.w3.org/1999/xhtml" href="http://www.google.com" title="Google Title">
Hyperlink
</a>
</Content>
</RichText>
XSLT-файл:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" method="xml" cdata-section-elements="script"></xsl:output>
<xsl:template match="/ | node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*">
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="*[ (self::br or self::p or self::div) and normalize-space(translate(., ' ', '')) = '' and not(@*) and not(processing-instruction()) and not(comment()) and not(*[not(self::br) or @* or * or node()]) and not(following::node()[not( (self::text() or self::br or self::p or self::div) and normalize-space(translate(., ' ', '')) = '' and not(@*) and not(processing-instruction()) and not(comment()) and not(*[not(self::br) or @* or * or node()]) )]) ]">
<!-- ignore all paragraphs and line-breaks at the end that have nothing but (non-breaking) spaces and line breaks -->
</xsl:template>
<xsl:template match="br[parent::div and not(preceding-sibling::node()) and not(following-sibling::node())]">
<!-- Chrome generates <div><br/></div>. Renders differently in different browsers. Replace it with a non-breaking space -->
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
Выход:
<?xml version="1.0" encoding="utf-8"?>
<RichText xmlns="uuid:e25b1476-ce87-4a67-a22b-b82a752810e0">
<Content>
<a xmlns="http://www.w3.org/1999/xhtml" href="http://www.google.com">
Hyperlink
</a>
</Content>
</RichText>