docbook-apps

  • 1.  stylesheet customization fails trying to strip a namespace prefix and some unwanted attributes

    Posted 11-11-2006 19:32
    Hi,
    I am trying to strip the mml: prefix from MathML elements. In
    addition, I need the xmlns:mml="some url" attribute to come through as
    xmlns="some url" and I need to eliminate the following attributes from
    the mml:math element: xmlns:mathematica and mathematica:form

    this is what i have so far:

    <xsl:template match="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
    <xsl:element name="{local-name(.)}">
    <xsl:for-each select="@mml:*">
    <xsl:attribute name="{local-name(.)}">
    <xsl:value-of select="."/>
    </xsl:attribute>
    </xsl:for-each>
    <xsl:for-each select="@xmlns:mml"
    xmlns:xmlns="http://www.w3.org/2000/xmlns/">
    <xsl:attribute name="xmlns">
    <xsl:value-of select="."/>
    </xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates/>
    </xsl:element>
    </xsl:template>

    it writes out the math element and its children unprefixed, but it
    also puts xmlns="" and form="TraditionalForm" in attributes of the
    math element

    (the original value of mathematica:form is TraditionalForm)

    How does one force the output to retain the MathML namespace and drop
    that form element?

    Thanks,

    --
    http://chris.chiasson.name/



  • 2.  Re: stylesheet customization fails trying to strip a namespace prefix and some unwanted attributes

    Posted 11-11-2006 22:33
    This puts the output tree in the correct namespace, but still leaves
    the form attribute...

    <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="http://www.w3.org/1998/Math/MathML">
    <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>

    On 11/11/06, Chris Chiasson <chris@chiasson.name> wrote:
    > Hi,
    > I am trying to strip the mml: prefix from MathML elements. In
    > addition, I need the xmlns:mml="some url" attribute to come through as
    > xmlns="some url" and I need to eliminate the following attributes from
    > the mml:math element: xmlns:mathematica and mathematica:form
    >
    > this is what i have so far:
    >
    > <xsl:template match="mml:*" xmlns:mml="http://www.w3.org/1998/Math/MathML">
    > <xsl:element name="{local-name(.)}">
    > <xsl:for-each select="@mml:*">
    > <xsl:attribute name="{local-name(.)}">
    > <xsl:value-of select="."/>
    > </xsl:attribute>
    > </xsl:for-each>
    > <xsl:for-each select="@xmlns:mml"
    > xmlns:xmlns="http://www.w3.org/2000/xmlns/">
    > <xsl:attribute name="xmlns">
    > <xsl:value-of select="."/>
    > </xsl:attribute>
    > </xsl:for-each>
    > <xsl:apply-templates/>
    > </xsl:element>
    > </xsl:template>
    >
    > it writes out the math element and its children unprefixed, but it
    > also puts xmlns="" and form="TraditionalForm" in attributes of the
    > math element
    >
    > (the original value of mathematica:form is TraditionalForm)
    >
    > How does one force the output to retain the MathML namespace and drop
    > that form element?
    >
    > Thanks,
    >
    > --
    > http://chris.chiasson.name/
    >


    --
    http://chris.chiasson.name/



  • 3.  RE: [docbook-apps] Re: stylesheet customization fails trying to strip a namespace prefix and some unwanted attributes

    Posted 11-12-2006 08:03
    > -----Original Message-----
    > From: Chris Chiasson
    >
    > This puts the output tree in the correct namespace, but still leaves
    > the form attribute...
    >
    > <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="http://www.w3.org/1998/Math/MathML">
    > <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>


    I hope that this will do the trick:

    <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="http://www.w3.org/1998/Math/MathML">

    <xsl:for-each
    select="@*[not(namespace-uri()='http://www.wolfram.com/XML/')]">
    <xsl:copy/>
    </xsl:for-each>

    <xsl:apply-templates/>
    </xsl:element>
    </xsl:template>

    </xsl:stylesheet>


    /MJ





  • 4.  Re: [docbook-apps] Re: stylesheet customization fails trying to strip a namespace prefix and some unwanted attributes

    Posted 11-12-2006 09:32
    Mauritz Jeanson,

    Many thanks :-]

    I don't know why my original namespace axis specifier didn't work on
    the attributes. Your uh, brackets code gave me an idea, which worked.
    I'm sure your code works, even though I didn't test it. BTW, good call
    on <xsl:copy> - at the time I had xsl:attribute, I didn't realize that
    the namespace prefix would be automatically removed.

    Here is what I went with:


    <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>


    On 11/12/06, Mauritz Jeanson <mj@johanneberg.com> wrote:
    > > -----Original Message-----
    > > From: Chris Chiasson
    > >
    > > This puts the output tree in the correct namespace, but still leaves
    > > the form attribute...
    > >
    > > <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="http://www.w3.org/1998/Math/MathML">
    > > <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>
    >
    >
    > I hope that this will do the trick:
    >
    > <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="http://www.w3.org/1998/Math/MathML">
    >
    > <xsl:for-each
    > select="@*[not(namespace-uri()='http://www.wolfram.com/XML/')]">
    > <xsl:copy/>
    > </xsl:for-each>
    >
    > <xsl:apply-templates/>
    > </xsl:element>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
    >
    > /MJ
    >
    >
    >


    --
    http://chris.chiasson.name/



  • 5.  RE: [docbook-apps] Re: stylesheet customization fails trying to strip a namespace prefix and some unwanted attributes

    Posted 11-12-2006 11:52
    > -----Original Message-----
    > From: Chris Chiasson

    > <xsl:for-each
    > select="@*[namespace-uri()=namespace-uri(parent::self)]">
    > <xsl:copy/>
    > </xsl:for-each>


    The parent::self thingy must be a mistake. I suppose you really meant
    parent::*. But that won't help, because attributes without a prefix will not
    be copied. Unprefixed attributes are not in any namespace, and the
    namespace-uri() function returns an empty string when applied to such
    attribute nodes.

    I think that my suggestion

    <xsl:for-each
    select="@*[not(namespace-uri()='http://www.wolfram.com/XML/')]">

    is what you should use. Then all attributes, except those in the Mathematica
    namespace, will be copied.

    /MJ