473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

removing a namespace prefix and removing all attributes not in that same prefix

Hi,
After reading and experimenting for a several hours, I have this
stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xmlns="http://www.w3.org/2000/xmlns/"
xmlns:mathematica="http://www.wolfram.com/XML/"
version="1.0">
<xsl:template match="mml:*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
<xsl:for-each select="@mml:*">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

which transforms this file

<?xml version="1.0" encoding="UTF-8"?>
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"
mathematica:form="TraditionalForm"
xmlns:mathematica="http://www.wolfram.com/XML/">
<mml:mstyle mathsize="10" fontfamily="Times New Roman">
<mml:mrow>
<mml:mi>F</mml:mi>
<mml:mo>=</mml:mo>
<mml:mrow>
<mml:msup>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
<mml:mn>2</mml:mn>
</mml:msup>
<mml:mo>-</mml:mo>
<mml:mrow>
<mml:mn>3</mml:mn>
<mml:mo>⁢</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
<mml:mo>⁢</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
</mml:mrow>
<mml:mo>+</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
<mml:mo>+</mml:mo>
<mml:mrow>
<mml:mn>4</mml:mn>
<mml:mo>⁢</mml:mo>
<mml:msup>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
<mml:mn>2</mml:mn>
</mml:msup>
</mml:mrow>
<mml:mo>-</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
</mml:mrow>
</mml:mrow>
</mml:mstyle>
</mml:math>

into this:

<?xml version="1.0"?>
<math xmlns="http://www.w3.org/1998/Math/MathML"
form="TraditionalForm">
<mstyle mathsize="10" fontfamily="Times New Roman">
<mrow>
<mi>F</mi>
<mo>=</mo>
<mrow>
<snip/>
</math>

as you can see, it does properly localize the MathML elements and
attributes. Unfortunately, it doesn't exclude the mathematica:form
attribute - it just localizes it. So, how can this attribute be
removed?

Thank you,

Nov 11 '06 #1
6 2030
Read about "identity rule" or "identity transformation"

Cheers,
Dimitre Novatchev

"Chris Chiasson" <ch************@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
Hi,
After reading and experimenting for a several hours, I have this
stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xmlns="http://www.w3.org/2000/xmlns/"
xmlns:mathematica="http://www.wolfram.com/XML/"
version="1.0">
<xsl:template match="mml:*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
<xsl:for-each select="@mml:*">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

which transforms this file

<?xml version="1.0" encoding="UTF-8"?>
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"
mathematica:form="TraditionalForm"
xmlns:mathematica="http://www.wolfram.com/XML/">
<mml:mstyle mathsize="10" fontfamily="Times New Roman">
<mml:mrow>
<mml:mi>F</mml:mi>
<mml:mo>=</mml:mo>
<mml:mrow>
<mml:msup>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
<mml:mn>2</mml:mn>
</mml:msup>
<mml:mo>-</mml:mo>
<mml:mrow>
<mml:mn>3</mml:mn>
<mml:mo>⁢</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
<mml:mo>⁢</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
</mml:mrow>
<mml:mo>+</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
<mml:mo>+</mml:mo>
<mml:mrow>
<mml:mn>4</mml:mn>
<mml:mo>⁢</mml:mo>
<mml:msup>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
<mml:mn>2</mml:mn>
</mml:msup>
</mml:mrow>
<mml:mo>-</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
</mml:mrow>
</mml:mrow>
</mml:mstyle>
</mml:math>

into this:

<?xml version="1.0"?>
<math xmlns="http://www.w3.org/1998/Math/MathML"
form="TraditionalForm">
<mstyle mathsize="10" fontfamily="Times New Roman">
<mrow>
<mi>F</mi>
<mo>=</mo>
<mrow>
<snip/>
</math>

as you can see, it does properly localize the MathML elements and
attributes. Unfortunately, it doesn't exclude the mathematica:form
attribute - it just localizes it. So, how can this attribute be
removed?

Thank you,

Nov 12 '06 #2
I started with an identity transformation to make what I already have.
The problem I am experiencing is that I am somehow misusing the
namespace axis of Xpath in a way that is giving me all the attributes
instead of just the ones in the MathML namespace.
Dimitre Novatchev wrote:
Read about "identity rule" or "identity transformation"

Cheers,
Dimitre Novatchev

"Chris Chiasson" <ch************@gmail.comwrote in message
news:11**********************@f16g2000cwb.googlegr oups.com...
Hi,
After reading and experimenting for a several hours, I have this
stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xmlns="http://www.w3.org/2000/xmlns/"
xmlns:mathematica="http://www.wolfram.com/XML/"
version="1.0">
<xsl:template match="mml:*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
<xsl:for-each select="@mml:*">
<xsl:attribute name="{local-name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

which transforms this file

<?xml version="1.0" encoding="UTF-8"?>
<mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML"
mathematica:form="TraditionalForm"
xmlns:mathematica="http://www.wolfram.com/XML/">
<mml:mstyle mathsize="10" fontfamily="Times New Roman">
<mml:mrow>
<mml:mi>F</mml:mi>
<mml:mo>=</mml:mo>
<mml:mrow>
<mml:msup>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
<mml:mn>2</mml:mn>
</mml:msup>
<mml:mo>-</mml:mo>
<mml:mrow>
<mml:mn>3</mml:mn>
<mml:mo>⁢</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
<mml:mo>⁢</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
</mml:mrow>
<mml:mo>+</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>1</mml:mn>
</mml:msub>
<mml:mo>+</mml:mo>
<mml:mrow>
<mml:mn>4</mml:mn>
<mml:mo>⁢</mml:mo>
<mml:msup>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
<mml:mn>2</mml:mn>
</mml:msup>
</mml:mrow>
<mml:mo>-</mml:mo>
<mml:msub>
<mml:mi>X</mml:mi>
<mml:mn>2</mml:mn>
</mml:msub>
</mml:mrow>
</mml:mrow>
</mml:mstyle>
</mml:math>

into this:

<?xml version="1.0"?>
<math xmlns="http://www.w3.org/1998/Math/MathML"
form="TraditionalForm">
<mstyle mathsize="10" fontfamily="Times New Roman">
<mrow>
<mi>F</mi>
<mo>=</mo>
<mrow>
<snip/>
</math>

as you can see, it does properly localize the MathML elements and
attributes. Unfortunately, it doesn't exclude the mathematica:form
attribute - it just localizes it. So, how can this attribute be
removed?

Thank you,
Nov 12 '06 #3
Mauritz Jeanson helped me out. Here a the solution:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:mathematica="http://www.wolfram.com/XML/"
version="1.0">
<xsl:template match="mml:*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
<xsl:for-each
select="@*[namespace-uri()=namespace-uri(parent::self)]">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

Nov 12 '06 #4
"a the" -"is a"
....

Chris Chiasson wrote:
Mauritz Jeanson helped me out. Here a the solution:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:mathematica="http://www.wolfram.com/XML/"
version="1.0">
<xsl:template match="mml:*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
<xsl:for-each
select="@*[namespace-uri()=namespace-uri(parent::self)]">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Nov 12 '06 #5
Actually, Mauritz Jeanson wrote me again to say that parent::self is
wrong. I don't know why it works in xsltrproc on windows, but it
shouldn't have.

Anyway,

the "right" xpath for the attributes is as follows:
@*[namespace-uri()='' or namespace-uri()=namespace-uri(parent::*)]

Chris Chiasson wrote:
Mauritz Jeanson helped me out. Here a the solution:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:mathematica="http://www.wolfram.com/XML/"
version="1.0">
<xsl:template match="mml:*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(.)}">
<xsl:for-each
select="@*[namespace-uri()=namespace-uri(parent::self)]">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Nov 14 '06 #6
In article <11**********************@e3g2000cwe.googlegroups. com>,
Chris Chiasson <ch************@gmail.comwrote:
>Actually, Mauritz Jeanson wrote me again to say that parent::self is
wrong. I don't know why it works in xsltrproc on windows, but it
shouldn't have.
parent::self will typically be an empty node set (unless the parent
happens to be called "self"), so namespace-uri(parent::self) will be
the empty string. That will "work" when the parent is in no
namespace.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 14 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Romeo Disca | last post by:
Hello newsgroup, i'm new to xml - what's wrong with this piece code here? i have these two files: test.xml ---- <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE a SYSTEM "test.ent"
1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
25
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound...
1
by: indo3 | last post by:
HELLO For the top root element of my schema file, i want to declare following attribute: <xs:attribute name="xmlns:m" type="xs:string" default="http://www.w3.org/1998/Math/MathML"/> But...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
2
by: Manoj G | last post by:
Hello, I believe there is no way to remove the default namespace declaration (For eg <DataSet xmlns="something">.... ) on an XmlNode object directly through DOM. So, what is the best way to...
3
by: JT | last post by:
Hi all, I have a pretty basic question... I have a method (below) which uses ExecuteXMLReader to load the output from a FOR XML Explicit stored procedure into an XML document, and then save the...
13
by: Axel Dahmen | last post by:
Hi, I've got a question on namespaces. After reading http://www.w3.org/TR/xml-names11 I still don't understand how namespaces are applied to attributes - particularly in regard to how processing...
9
by: Mark Olbert | last post by:
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c. The problem I'm running into is that the root element needs to be unqualified,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.