Re: [xsl] how to remove xmls=""

Subject: Re: [xsl] how to remove xmls=""
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 4 Sep 2019 08:04:22 -0000
You have copied the <front> and <body> elements from the source document,
where they are in no namespace, so the serializer has to add the xmlns=""
attribute to prevent the elements inheriting the namespace of their new
parent.

It seems you actually want the <front> and <body> elements to be in namespace
"http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpublishing.xsd";
<http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpublishing.xsd%
22>, so you must generate them in that namespace. That means you can't simply
copy them from the input. So the template rule that copies these elements
shouldn't use <xsl:copy>, it should use <xsl:element name="{local-name()}"
namespace="http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpubli
shing.xsd
<http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpublishing.xsd%
22>">.

I see that you've experimented with the copy-namespaces and inherit-namespaces
attributes of xsl:copy. I would suggest you avoid using these specialist
attributes until you have a much better understanding of how namespace nodes
and in-scope namespaces are handled by the XDM data model.

Michael Kay
Saxonica

> On 4 Sep 2019, at 07:03, Joga Singh Rawat jrawat@xxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Dear Expert,
> I am getting <front xmlns=""> and <body xmlns=""> as output from below
combination of input xml and xslt. Please let us know how to remove
xmlns=bb.
>
> INPUT
> <article xmlns:mml="http://www.w3.org/1998/Math/MathML";
<http://www.w3.org/1998/Math/MathML%22>
xmlns:xlink="http://www.w3.org/1999/xlink";
<http://www.w3.org/1999/xlink%22>xmlns:oasis="http://www.niso.org/standards/z
39-96/ns/oasis-exchange/table"
<http://www.niso.org/standards/z39-96/ns/oasis-exchange/table%22>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
<http://www.w3.org/2001/XMLSchema-instance%22>xmlns:ali="http://www.niso.org/
schemas/ali/1.0/" <http://www.niso.org/schemas/ali/1.0/%22>
article-type="research-article" dtd-version="1.1" xml:lang="en">
> <front>
> ...
> </front>
> <body>
> ...</body>
> </article>
>
> XSLT
> <xsl:template match="article">
>     <article
xmlns="http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpublishin
g.xsd"
<http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpublishing.xsd%
22>>
>         <xsl:if test="@article-type">
>             <xsl:attribute name="article-type" select="@article-type"/>
>         </xsl:if>
>         <xsl:if test="@xml:lang">
>             <xsl:attribute name="xml:lang" select="@xml:lang"/>
>         </xsl:if>
>         <xsl:attribute
name="xsi:schemaLocation">http://specifications.silverchair.com/xsd/1/19/SCJA
TS-journalpublishing.xsd
<http://specifications.silverchair.com/xsd/1/19/SCJATS-journalpublishing.xsd>
http://specifications.silverchair.com/xsd/1/19/SCJATS-journalpublishing.xsd
<http://specifications.silverchair.com/xsd/1/19/SCJATS-journalpublishing.xsd>
</xsl:attribute>
>         <xsl:apply-templates/>
>     </article>
> </xsl:template>
>
> <xsl:template match="node() | @*">
>     <xsl:copy copy-namespaces="no" inherit-namespaces="no">
>         <xsl:apply-templates select="node() | @*[not(name()='xmlns')]"/>
>     </xsl:copy>
> </xsl:template>
>
> OUTPUT
> <article
xmlns="http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpublishin
g.xsd"
<http://specifications.silverchair.com/xsd/1/18/SCJATS-journalpublishing.xsd%
22>
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
<http://www.w3.org/2001/XMLSchema-instance%22>
>          xmlns:mml="http://www.w3.org/1998/Math/MathML";
<http://www.w3.org/1998/Math/MathML%22>
>          article-type="research-article"
>          xml:lang="en"
>
xsi:schemaLocation="http://specifications.silverchair.com/xsd/1/19/SCJATS-jou
rnalpublishing.xsd
<http://specifications.silverchair.com/xsd/1/19/SCJATS-journalpublishing.xsd>
http://specifications.silverchair.com/xsd/1/19/SCJATS-journalpublishing.xsd";
<http://specifications.silverchair.com/xsd/1/19/SCJATS-journalpublishing.xsd%
22>>
>    <front xmlns="">
>     ...
>    </front>
>    <body xmlns="">
>    ...
> </body>
> </article>
>
> thanks in advance
> ...JSR
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread