Jump to content

transformation and namespaces


obiwankenobi
 Share

Recommended Posts

hello everyonemore than a problem this is a question - for I've already fixed the problem in a "dirty" way, but I'd like to find out from which is generated.this is my xml<myroot xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somethingcom/"><tag1>something</tag1><tag2><tag3>something'>http://www.somethingcom/"><tag1>something</tag1><tag2><tag3>something else</tag3><tag3>something else more</tag3></tag2></myroot>and here's the xsl<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><p>Tag One: <xsl:value-of select="//tag1"></p><xsl:for-each select="/myroot/tag2/*"><p>middle tags: <xsl:value-of select="tag3"/></p></xsl:for-each></body></html></xsl:template>when I try to transform it, if there's the namespace attribute (xmlns="http://www.somethingcom/") no matter what I do, no tag is read (even if I try to reach the tag by the absolute xpath "//tag1"). If I remove the attribute "xmlns", it works perfectly.Can anyone explain me what I'm supposed to do to have it be read even with that atttribute?Thanks bunchJedi MasterObi-Wan KenobiMay the Force be with you

Link to comment
Share on other sites

I don't know too much about namespaces and their effects on XSL,but what I have found is that it is more successful to create a template for each element and then have the root template apply them all:<xsl:template match="/"><html><body><xsl:apply-templates /></body></html></xsl:template><xsl:template match="tag1"><p>Tag One: <xsl:value-of select="tag1"><p></xsl:template><xsl:template match="tag3"><p>middle tags: <xsl:value-of select="tag3"/></p></xsl:template>This way, you don't need to use the <xsl:for-each> because the template will apply every time it encounters an element called tag3.Give it a go and let me know if it helps.Dooberry.

Link to comment
Share on other sites

It works now (blessed be templates!) but still the problem remains.What's wrong with namespaces? I saw that if I try to reach the nodes by the name() and node() functions, they work, but no absolute or relative paths are accepted.So, basically, the question is, how to deal with xmlns?thanks again dude, much appreciated :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...