how to get rid of the namespace in the xml while transforming xsl

because of namespace in the xml,I could get the output .how to get rid of the namespace while transforming xsl.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employeeResponse xmlns="http://example.com/xml">
    <employee>
        <employeeId>1</employeeId>
     </employee>
    <employee>
        <employeeId>2</employeeId>
    </employee>
   </employeeResponse>
   
   xsl
   ****
   
   
   <?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>Telecast Report</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>employeeId</th>
     
      </tr>
      <xsl:for-each select="employeeResponse/employee">
        <tr>
          <td><xsl:value-of select="employeeId"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>
LVL 20
chaitu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:egx="http://example.com/xml"
     exclude-result-prefixes="egx"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:template match="/">
        <html>
            <body>
                <h2>Telecast Report</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>employeeId</th>
                        
                    </tr>
                    <xsl:for-each select="egx:employeeResponse/egx:employee">
                        <tr>
                            <td><xsl:value-of select="egx:employeeId"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
    
</xsl:stylesheet> 

Open in new window

0
Geert BormansInformation ArchitectCommented:
Give a random prefix to the namespace in the XSLT (recommended not to leave the default namespace for the result tree)
and use the prefix in each XPath statement
(note that I also excluded the prefix from teh result tree)

Basically what I am doing in the above example... I address each element in its namespace, not in the null namespace,
because by inheretance each element in the source document belongs to that namespace
0
chaitu chaituAuthor Commented:
i have few clarifications.

1)"recommended not to leave the default namespace for the result tree."
are you talking abt  xmlns:egx="http://example.com/xml"?

2)"note that I also excluded the prefix from teh result tree"
what is result tree here and what is null namespace?
0
Geert BormansInformation ArchitectCommented:
Well, I think you can check out some basics on namespaces here
http://www.w3schools.com/xml/xml_namespaces.asp
(the site is pretty vague and at some points close to incorrect, but it gives a first step into understanding namespaces,
the site also explains the concept of a default namespace, the namespace in use when there is no prefix,
however the site fails on exlaining the concept of null namespace or no namespace triggered by xmlns="")
Also this one is interesting reading material
http://en.wikipedia.org/wiki/XML_namespace

When I write 1)...
a namespace can be indicated by a prefix or by no prefix (no prefix being the default namespace)
a prefix can only be bound to one namespace at the same time, the same aplies to the default namespace
in your example, there is a default namespace binding, so each unprefixed element name in the source document actualy puts that element in this namespace "http://example.com/xml"
That is for the source.
An XSLT builds up a result tree (eventually your output)
If you don't want each element in the output tree in a specific namespace, the result tree will occupy the no prefix (default) namespace. That simply implies that you need a prefix for the source namespace
In my solution I used
xmlns:egx="http://example.com/xml"
instead of
xmlns="http://example.com/xml"
for that reason

2) The result tree again is the output, there is no namespace in the result, so the elements are in the null namespace
exclude-result-prefixes="egx"
makes sure that the egx namespace binding is not copied to the result
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.