Re: [xsl] problem with transforming mixed content

Subject: Re: [xsl] problem with transforming mixed content
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 15 Aug 2020 07:23:10 -0000
Am 15.08.2020 um 08:46 schrieb Wolfhart Totschnig
wolfhart.totschnig@xxxxxxxxxxx:
Dear Gerrit,

Thank you for the explanation! I understand now why I get the @xmlns
attribute with Dimitre's solution. But I still don't understand why I
also get it with Graydon's solution, which does not use <xsl:copy> but
serialize() followed by parse-xml-fragment(). In the input data, the
@xmlns attribute is not on the <i> element itself but on an ancestor
element several levels up. Why then does it show up in the result of
serialize()? And how do I get rid of it using Graydon's approach?

Neither serialization nor parsing loses any namespaces present in the input tree so while your input markup might have a namespace declaration high up in the tree each node in the tree carries its namespace information and if you have serialize and parse the namespace information is preserved.

As for stripping namespaces, that is usually done in a mode

<xsl:template match="*" mode="strip-namespace">
  <xsl:element name="local-name()">
     <xsl:apply-templates select="@* | node()" mode="#current"/>
  </xsl:element>
</xsl:template>

and then e.g.

<xsl:apply-templates select="serialize(node()) => substring-before(':')
=> lower-case() => parse-xml-fragment()" mode="strip-namespace"/>

instead of a simple xsl:sequence.



If that doesn't work you might want to summarize which input you have
and how your current XSLT based on Graydon's suggestion looks, plus the
result you want and the one you get.

Current Thread