admin管理员组文章数量:1379944
I have this XML
<?xml version="1.0" encoding="UTF-8"?>
<item xmlns="; version="2.2" xml:lang="en-us">
<head>
<title>Scope of application</title>
<id>a71ad0e3e1ed569595c88b60421846ee</id>
<version>2</version>
</head>
<body lang="en">
<section id="d29e3458" data-class="portrait smo-chapter-orientation-portrait smo-chapter-numbering-no numbering-no lvl- 1" data-type="Chapter">
<p class="smo-hide" data-role="heading" id="d29e3461">System requirements</p>
<div data-role="block" id="d29e3525"/>
</section>
</body>
</item>
Which I am transforming to this html via XSLT 2.0
Output:
<!DOCTYPE HTML>
<html xmlns=";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Scope of application</title>
<meta name="id" content="32a80e1803f0966289c5c7d3075abcd8"/>
</head>
</html>
This is my stylesheet:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl=";
xml:lang="en"
xmlns=";
xpath-default-namespace=";
exclude-result-prefixes=""
>
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="/*">
<html>
<xsl:apply-templates select="*" />
</html>
</xsl:template>
<!-- other template rules, omitted for readability -->
</xsl:stylesheet>
I want to get rid of the xmlns=" in the output, but I don't know how to achieve this. exclude-result-prefixes="" doesn't work.
Could someone please guide me? Thank you.
I have this XML
<?xml version="1.0" encoding="UTF-8"?>
<item xmlns="http://www.p-corp/ns/pyxml" version="2.2" xml:lang="en-us">
<head>
<title>Scope of application</title>
<id>a71ad0e3e1ed569595c88b60421846ee</id>
<version>2</version>
</head>
<body lang="en">
<section id="d29e3458" data-class="portrait smo-chapter-orientation-portrait smo-chapter-numbering-no numbering-no lvl- 1" data-type="Chapter">
<p class="smo-hide" data-role="heading" id="d29e3461">System requirements</p>
<div data-role="block" id="d29e3525"/>
</section>
</body>
</item>
Which I am transforming to this html via XSLT 2.0
Output:
<!DOCTYPE HTML>
<html xmlns="http://www.p-corp/ns/pyxml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Scope of application</title>
<meta name="id" content="32a80e1803f0966289c5c7d3075abcd8"/>
</head>
</html>
This is my stylesheet:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3./1999/XSL/Transform"
xml:lang="en"
xmlns="http://www.p-corp/ns/pyxml"
xpath-default-namespace="http://www.p-corp/ns/pyxml"
exclude-result-prefixes=""
>
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="/*">
<html>
<xsl:apply-templates select="*" />
</html>
</xsl:template>
<!-- other template rules, omitted for readability -->
</xsl:stylesheet>
I want to get rid of the xmlns="http://www.p-corp/ns/pyxml in the output, but I don't know how to achieve this. exclude-result-prefixes="" doesn't work.
Could someone please guide me? Thank you.
Share Improve this question edited Mar 21 at 18:13 ondrums asked Mar 20 at 7:34 ondrumsondrums 17812 bronze badges 9 | Show 4 more comments1 Answer
Reset to default 1Using an identity transform, with a specialized template for elements that constructs an element using the local-name()
(which will produce an element without that namespace) rather than xsl:copy
(which would preserve the namespace) from the default template match.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3./1999/XSL/Transform"
xml:lang="en">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
本文标签: xmlHow can I omit a namespace in xslt outputStack Overflow
版权声明:本文标题:xml - How can I omit a namespace in xslt output? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744425249a2605655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
xmlns="http://www.p-corp/ns/pyxml"
? That will certainly put that literal result<html>
element that you have in that namespace. – Martin Honnen Commented Mar 20 at 11:35