xsl-list
[Top] [All Lists]

Re: Changing prefix

2004-05-19 12:59:04
Nicolas,

David (Dr MathML) will probably be along shortly, but....

As you may know, XSLT (or any XML-namespace-conformant system) doesn't distinguish between elements on the basis of their prefixes, but on the basis of the expanded name when those prefixes are resolved to their URI bindings. So if you have

<example xmlns:n1="myURL.com" xmlns:n2="myURL.com">
  <n1:element/>
  <n2:element/>
</example>

n1:element and n2:element are considered to be the same.

What this means is that you really only need an identity transform that writes your output using the prefix you want.

This can probably be done (although I haven't tried it) very simply:

<xsl:stylesheet  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:math="http://www.w3.org/1998/Math/MathML ">

<xsl:template match="/">
  <xsl:copy-of select="/"/>
</xsl:template>

</xsl:stylesheet>

This will work since the "math" prefix here is bound to the same URI as the "mml" prefix in your input. (I'm assuming your input declares the correct namespace. :-) And most XSLT engines should serialize the result using the prefix you have chosen, "math". (Note however that strictly speaking they don't have to do this: in effect you are relying on an optional feature of the serializer, and you should test the technique on any processor before depending on its working there.)

Cheers,
Wendell

At 03:53 PM 5/19/2004, you wrote:
 I have an app that uses MathML, and gathers some stats from it.
 But i ran into a problem when using mml tags embedded in docbook,
 as this app uses the "math" prefix, and in docbook mathml tags
 are prefixed with "mml".

 I am trying to do a stylesheet that copies all mathml elements,
 including attributes, data etc.. just changing the prefix.

 Any idea ?
 Nicolas


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================



<Prev in Thread] Current Thread [Next in Thread>