I found many solution for this problem on internet (and in this forum too), but still I can resolve my problem.
I have this code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="#default">
<xsl:output omit-xml-declaration="yes" standalone="no" method="xml" indent="no" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tei:body">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<back>
<div>
<xsl:for-each select="//tei:rs[@type='luogo']">
<p><xsl:value-of select="."/></p>
</xsl:for-each>
</div></back>
</xsl:template>
</xsl:stylesheet>
The output is correct except for the back section, that repeats the xmlns and xmlns:tei attributes:
<back xmlns="" xmlns:tei="http://www.tei-c.org/ns/1.0"><div>....</div></back>
they are already here (so I don’t need the “back” ones):
<TEI xmlns="http://www.tei-c.org/ns/1.0">
I tried codes like this:
<xsl:template match="@*|node()[not(self::*)]">
<xsl:copy/>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
Or this:
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|*"/>
</xsl:element>
</xsl:template>
<xsl:template match="tei:back">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
I even changed it to make it fit in my code, changing the match or the value of select with “tei:back”, it doesn’t worked.
What I have to do in order to make the tei namespace appear only in the section?
Thank you in advice for your help!
Edit:
Thank you for the answers.
My xml code is like this:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="file:/C:/Users/User/Desktop/prova2.xsl"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader><fileDesc>
<titleStmt>
<title>AA</title>
</titleStmt>
<publicationStmt><p><!-- supply publication information --></p></publicationStmt>
<sourceDesc>
<bibl>AA</bibl>
</sourceDesc>
</fileDesc><profileDesc>
<langUsage>
<language ident="ita">AA</language>
<language ident="lat">AA</language>
</langUsage>
</profileDesc></teiHeader>
<text>
<body>
<div type="book" n="3" xml:id="L3">
<head>AA
</head>
<div type="cap" n="1" xml:id="L3-01">
<head>AA</head>
<p>AA
<pb n="200"/>AA
</p>
</div>
</div>
</body>
</text>
</TEI>
The complete output is like this:
<?xml-stylesheet type="text/xsl" href="file:/C:/Users/User/Desktop/prova2.xsl"?><TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader><fileDesc>
<titleStmt>
<title>AA</title>
</titleStmt>
<publicationStmt><p><!-- supply publication information --></p></publicationStmt>
<sourceDesc>
<bibl>AA</bibl>
</sourceDesc>
</fileDesc><profileDesc>
<langUsage>
<language ident="ita">AA</language>
<language ident="lat">AA</language>
</langUsage>
</profileDesc></teiHeader>
<text>
<body>
<div type="book" n="3" xml:id="L3">
<head>AA
</head>
<div type="cap" n="1" xml:id="L3-01">
<head>AA</head>
<p>AA
<pb n="200"/>AA
</p>
</div>
</div>
</body><back xmlns="" xmlns:tei="http://www.tei-c.org/ns/1.0"><div/></back>
</text>
</TEI>
The issue occurs because in your input XML document, all the elements have been specified to be within the namespace “http://www.tei-c.org/ns/1.0”. However, in your XSLT, you are creating new elements (in the
tei:bodytemplate) but you are not specifying the namespace of the new elements. This means the new elements, such asbackcreated without a namespace, and so the output XML contains the extra namespace tags to indicate this.One way to resolve this is to specify the namespace when creating the element. Instead of doing this….
Do this….
Here is the full XSLT
When applied to your sample XML, the following is output