Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > removing a namespace prefix and removing all attributes not in that same prefix

Reply
Thread Tools

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

 
 
Chris Chiasson
Guest
Posts: n/a
 
      11-12-2006
Hi,
After reading and experimenting for a several hours, I have this
stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlnsmlns="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,

 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      11-12-2006
Read about "identity rule" or "identity transformation"

Cheers,
Dimitre Novatchev

"Chris Chiasson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi,
> After reading and experimenting for a several hours, I have this
> stylesheet:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
> xmlns:mml="http://www.w3.org/1998/Math/MathML"
> xmlnsmlns="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,
>



 
Reply With Quote
 
 
 
 
Chris Chiasson
Guest
Posts: n/a
 
      11-12-2006
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > Hi,
> > After reading and experimenting for a several hours, I have this
> > stylesheet:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
> > xmlns:mml="http://www.w3.org/1998/Math/MathML"
> > xmlnsmlns="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,
> >


 
Reply With Quote
 
Chris Chiasson
Guest
Posts: n/a
 
      11-12-2006
Mauritz Jeanson helped me out. Here a the solution:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlnssl="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>

 
Reply With Quote
 
Chris Chiasson
Guest
Posts: n/a
 
      11-12-2006
"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 xmlnssl="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>


 
Reply With Quote
 
Chris Chiasson
Guest
Posts: n/a
 
      11-14-2006
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 xmlnssl="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>


 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      11-14-2006
In article <(E-Mail Removed). com>,
Chris Chiasson <(E-Mail Removed)> wrote:

>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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Fixed/default attributes in Xerces: Namespace prefix missing?... VanOrton XML 2 11-30-2005 03:17 PM
redeclare the same namespace prefix? KJ XML 6 09-23-2005 08:16 PM
"static" prefix - to parallel "this" prefix Tim Tyler Java 36 12-10-2004 01:02 AM
Tag prefix and namespace heidi ASP .Net 0 11-02-2003 07:05 PM



Advertisments