xmlns menace

Posted on 2004-12-01
Last Modified: 2013-11-19
following is the xml file which i pass to xsl created by me.

<?xml version="1.0" ?>
<a xmlns="http://blah.blah/blah">
      <name>again blah</name>

now if i dont put xmlns attribute in xml, xsl outputs the html
in desired format. but if i put it just simply displays the values
of xml elements..
so my question is that how do i make my xsl ignore that xmlns attribute of
root element of the xml file?? i have tried google for hrs , but
i dint get anything.. so please can somebody help with it??
Question by:ghatlodia
    LVL 52

    Expert Comment

    by:Carl Tawn
    If you want to simply ignore the namespace (which probably isn't the best solution) then you can simply make your templates match on local-name(), something like:

    <xsl:template match="*[local-name()='a']">
        <!-- Other stuff here -->

    The better way to do it is to define an alias for the namespace in you xsl, something like:

        <xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:x="http://blah.blah/blah">

            <xsl:template match="x:a">
                <xsl:value-of select="x:name" />


    Hope this helps.
    LVL 1

    Author Comment

    thanks a lot for your reply..
    this is first time ,i am using xslt. now the solution  u gave me
    will work.. but the thing is that xml file which  i am getting is from
    web service and each time i get different segment of xml. what i mean is that
    there is only one schema,but each time i will get different part of it. so for me the root
    element of xml will vary each time. in that case , i dont know how to
    implement your solution..
    should i go for variable kind of thing or should i just write xsl for whole xml file
    according to schema ??
    i would really appreciate , if u could tell me that.

    About following xml that u gave

    <xsl:template match="*[local-name()='a']">
        <!-- Other stuff here -->

    what should i put at "other stuff" ? sorry i dint get that.


    LVL 52

    Accepted Solution

    Thing thing with XSL is that it is a big pattern matching engine.  All you need to do is write templates to handle and nodes that you are interested in.  This is flexible because you can have templates for nodes that may or may not be in the XML.

    How you format your XSL depends entirely on what you need to do.

    Probably the best thing to do would be to, like you said, write an XSL based on the schema.  Once you're more comfortable with XSL you can always go back and rework it or remove the bits you don't need.

    You can start by replacing <!-- Other stuff here --> with <xsl:apply-templates />.  This tells the parser to start processing all the child nodes of the current node (if that makes sense).

    Hope this helps.
    LVL 1

    Author Comment

     i tried the other solution that u suggested would be better. and it rocks now
    i cant thank u enough, man..
    again thanks a lot..

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    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…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now