• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1147
  • Last Modified:

xmlns menace

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>
</a>

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??
0
ghatlodia
Asked:
ghatlodia
  • 2
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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 -->
</xsl:template>

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="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://blah.blah/blah">

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

    </xsl:stylesheet>

Hope this helps.
0
 
ghatlodiaAuthor Commented:
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 -->
</xsl:template>

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

thanks

0
 
Carl TawnSystems and Integration DeveloperCommented:
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.
0
 
ghatlodiaAuthor Commented:
carl_tawn,
 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..
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now