• Post Reply Bookmark Topic Watch Topic
  • New Topic

XSLT:XML Auto-Add undesirable xmlns declaraction  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing an xml transform within a jsp page. I'm getting undesirable xmlns declaractions.

Here is part of my xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://xml.apache.org/html" exclude-result-prefixes="html">
<xslutput method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="yes"/>
<xsl:template match="/">
<table width="100%">
<xsl:for-each select="dai">
<th><b><em><xsl:variable name="status" select="clientSection/client/@status"/>
<xsl:if test="contains($status,'inactive')">
INACTIVE RECORD
</xsl:if>
</em></b></th>
<tr><td><h2>A. Client </h2></td></tr>
<tr><td><b>1. Client: </b> <u><html:text property="client" value="{clientSection/client}"/> </u></td><td><b>Loc: </b>
<u><html:text property="location" value="{clientSection/location}"/></u></td>

And here is part of my xml:
<?xml version="1.0" encoding="UTF-8" ?>
- <dai>
- <clientSection>
<client status="active">test2</client>
<location>test2 town</location>

When I do the transformation the result is:
<html lang="en">
<head>
<title>Add Direct Access Implementation Record</title>
</head>
<form name="dais1Form" method="post" action="/DaisStruts/dais1.do">
<input type="submit" name="home" value="Home">
</form>
<form name="dynaAddForm" method="post" action="/DaisStruts/dynaAdd.do">
<input type="submit" name="add" value="Add">
</form>
<body>
<CENTER><H2>Adding New Direct Access Implementation Record</H2></CENTER>
<table width="100%"><th><b><em/></b></th><tr><td>
<h2>A. Client </h2></td></tr><tr><td><b>1. Client: </b><u>
<html:text xmlns:html="http://xml.apache.org/html" value="test2" property="client"/></u></td><td><b>Loc: </b><u>
<html:text xmlns:html="http://xml.apache.org/html" value="test2 town" property="location"/></u></td>

Note the xmlns:html="http://xml.apache.org/html" inserted in the html:text.

How can I eliminate this?
Thanks,
Dave
 
Sheriff
Posts: 23429
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want that element to look like this instead?

<text value="test2" property="client"/>

Then change your XSLT to write it that way. Right now you explicitly write it out with the namespace.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My xsl is coded like this:
<html:text property="client" value="{clientSection/client}"/>
This transform inserts the errant namespace entry.
 
Paul Clapham
Sheriff
Posts: 23429
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a namespace prefix then you must have a namespace declaration for that prefix. If you don't want namespace declarations, then don't use prefixes.
 
Dave Clemmons
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't this the declaration:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://xml.apache.org/html" exclude-result-prefixes="html">
<xslutput method="xml" version="1.0" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="yes"/>

I am new to xml programming so bear with me.
 
Paul Clapham
Sheriff
Posts: 23429
46
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's the declaration in your stylesheet. Since you use the html: prefix in your stylesheet, and since you declare the namespace in the root element, that's fine.

But you're also using the html: prefix in the XML document you're generating. And therefore that document requires a namespace declaration for that prefix. Since the transformer is supposed to generate only correct XML, it generates the namespace declaration. Note that namespace declarations have a context, namely they apply in the element where they are located and in all that element's descendants, unless an overriding declaration appears in one of those descendants. So it's correct for the transformer to put the declaration in the same elements where the namespace is used, the declaration doesn't have to be in the root element.

But I still don't understand what your goal is here. If you don't want to generate an element in a namespace, then just don't do that. As I suggested in my original reply. What's wrong with that solution?
 
Dave Clemmons
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a java app using struts with dynaforms. I was told that the dynaform required jstl so that is why I'm using the form html:text.
Thanks,
Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!