[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Adding attributes on-the-fly through XSL

Posted on 2003-11-20
3
Medium Priority
?
397 Views
Last Modified: 2013-11-19
After generating an XML through an XSL transformation on another XSL, if I want to add (on-the-fly) the namespace and schema location attributes to the root element of the generated XML file, then how do I go about it? I used <xsl:attribute> as follows.

<xsl:attribute name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>
<xsl:attribute name="xsi:noNamespaceSchemaLocation">myschema.xsd</xsl:attribute>

This generates warning/error on the XML transformation engine (using javax.xml.transform.*) saying that I have used illegal attribute names. How to insert those attributes then?

Thanks a lot in advance.
0
Comment
Question by:xtremebytes2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:sparkplug
ID: 9788276
You can't add the namespace of the fly. You can however add all the namespaces you might use to the <xsl:stylesheet> element. These will be replicated in the output. The noNamespaceSchemaLocation attribute can be dynamically generated providing the namespace has been defined.

The following is an example of how this would be done:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="/">
      <root>
      <xsl:attribute name="xsi:noNamespaceSchemaLocation"><xsl:value-of select="@schemaFileName"/></xsl:attribute>
      </root>
</xsl:template>
</xsl:stylesheet>

Hope this helps.

>S'Plug<
0
 
LVL 9

Accepted Solution

by:
sparkplug earned 200 total points
ID: 9788616
Or maybe you can dynamically add the namespace too...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
      <root><xsl:attribute name="xsi:noNamespaceSchemaLocation" namespace="http://www.w3.org/2001/XMLSchema-instance">myschema.xsd</xsl:attribute>
      </root>
</xsl:template>
</xsl:stylesheet>

See also:

http://www.xslt.com/xsl-list/2002-09/msg00658.html

>S'Plug<
0
 
LVL 1

Author Comment

by:xtremebytes2002
ID: 9789033
thanks a lot spark plug
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question