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

Discussion in 'XML' started by Chris Chiasson, Nov 12, 2006.

  1. 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, Nov 12, 2006
    #1
    1. Advertising

  2. Read about "identity rule" or "identity transformation"

    Cheers,
    Dimitre Novatchev

    "Chris Chiasson" <> wrote in message
    news:...
    > 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, Nov 12, 2006
    #2
    1. Advertising

  3. 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" <> wrote in message
    > news:...
    > > 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, Nov 12, 2006
    #3
  4. 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, Nov 12, 2006
    #4
  5. "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, Nov 12, 2006
    #5
  6. 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>
     
    Chris Chiasson, Nov 14, 2006
    #6
  7. In article <>,
    Chris Chiasson <> 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.
     
    Richard Tobin, Nov 14, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. heidi

    Tag prefix and namespace

    heidi, Nov 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    357
    heidi
    Nov 2, 2003
  2. Tim Tyler
    Replies:
    36
    Views:
    1,471
    Darryl L. Pierce
    Dec 10, 2004
  3. KJ
    Replies:
    6
    Views:
    518
  4. VanOrton
    Replies:
    2
    Views:
    2,557
    VanOrton
    Nov 30, 2005
  5. roenick97

    SOAP and prefix namespace

    roenick97, Nov 23, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    172
    roenick97
    Nov 23, 2006
Loading...

Share This Page