Reputation: 37
I have the following xml:
<article article-type="research-article">
<body>
<graphic xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf" />
</body>
</article>
I need to convert this to:
<article article-type="research-article" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<body>
<graphic xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf" xmlns:xlink="http://www.w3.org/1999/xlink"/>
</body>
</article>
I used the following command in XSLT 2.0 for each of the elements for which namespace attribute is required:
<xsl:namespace name="xlink" select="'http://www.w3.org/1999/xlink'"/>
<xsl:namespace name="mml" select="'http://www.w3.org/1998/Math/MathML'"/>
But the issue is I am getting the namespace attribute only for one element i.e. article
. I have declared the namespaces at the beginning of my xslt as well. Can't figure out what is the exact issue. Help of any kind would be truly appreciated. Thanks.
Upvotes: 0
Views: 235
Reputation: 280
XML generators are not supposed to do what you want. They will produce your XML according to the specs. It is not recommended that you define the same namespaces in all elements that are using them! this makes it verbose, ugly and weird way of doing tings.
What is the problem if the namespace is defined only at the top (root element)? You can use it only in the elements that require it. simple.
(OP's comment: I need it at the root and I have declared it. But it is not available for the nodes under it i.e graphic and self-uri in my case). Have you checked if you xml is well-formed? If what you post here is the complete xml, then graphic and self-uri should always have the namespace available. You should aim for the following output for the reasons told above.
<article article-type="research-article" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<body>
<graphic xlink:href="zee9991370930006.g.eps"/>
<self-uri xlink:title="pdf" xlink:href="zee00813002857.pdf"/>
</body>
</article>
Upvotes: 0