Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   removing a namespace prefix and removing all attributes not in that same prefix (http://www.velocityreviews.com/forums/t392469-removing-a-namespace-prefix-and-removing-all-attributes-not-in-that-same-prefix.html)

Chris Chiasson 11-12-2006 12:10 AM

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,


Dimitre Novatchev 11-12-2006 04:05 AM

Re: removing a namespace prefix and removing all attributes not in that same prefix
 
Read about "identity rule" or "identity transformation"

Cheers,
Dimitre Novatchev

"Chris Chiasson" <chris.chiasson@gmail.com> wrote in message
news:1163290233.900093.276460@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,
>




Chris Chiasson 11-12-2006 05:49 AM

Re: removing a namespace prefix and removing all attributes not in that same prefix
 
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" <chris.chiasson@gmail.com> wrote in message
> news:1163290233.900093.276460@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,
> >



Chris Chiasson 11-12-2006 09:33 AM

Re: removing a namespace prefix and removing all attributes not in that same prefix
 
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>


Chris Chiasson 11-12-2006 09:34 AM

Re: removing a namespace prefix and removing all attributes not in that same prefix
 
"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>



Chris Chiasson 11-14-2006 04:27 PM

Re: removing a namespace prefix and removing all attributes not in that same prefix
 
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>



Richard Tobin 11-14-2006 05:08 PM

Re: removing a namespace prefix and removing all attributes not in that same prefix
 
In article <1163521628.708899.117910@e3g2000cwe.googlegroups. com>,
Chris Chiasson <chris.chiasson@gmail.com> 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.


All times are GMT. The time now is 08:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.