tags:

views:

72

answers:

1

Hi everyone,

I have an XML file that I want to transform using an XSLT. It only works when I remove all the attributes from the following part of the XML file:

<DiscoveryClientData 
  xmlns="http://www.frontrange.com/centennial/discovery" 
  SchemaVersion="0.6" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.frontrange.com/centennial/discovery DiscoveryClientData-0.6.xsd"
/>

The XSLT starts off like this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
      <xsl:template match="DiscoveryClientData">

Does anyone have any idea why this might be failing? The failure is that it doesn't place any element tags around the transformed data, it just spits it all out in one continuous string.

Thanks!

Edit: Ok, the example given below works, but is there a way I can define the prefix only once in the XSLT file? So I don't have to re-write my whole XSLT file? Thanks.

+4  A: 

Your XML is not in the default namespace, so your XSLT does not find any nodes to process.

Check Here for how to assign a namespace to the XSL template.

Adding this by popular demand. Taken from: Here

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:b="urn:xmlns:25hoursaday-com:bookstore">

<xsl:template match="b:bookstore">
<book-titles>
<xsl:apply-templates select="b:book/b:title"/>
</book-titles>
</xsl:template>

<xsl:template match="b:title"> 
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
GrayWizardx
I'd upvote you if you'd include an example of how to do this instead of referring ot the standard.
John Saunders
Yeah - me too - an example would be great - the standard is huuuuge!
Annie
Yeah, I should have done that. I was trying to find one. on w3school that was more concise.
GrayWizardx
Hey, thanks for the example - it works that way, but is there any way I can do it without having to match everything with the b: prefix? Like maybe just declare it once and go from there?
Annie
Might be able to use the default namespace. just use xmlns without a prefix. Not sure if it will work though. Namespaces are a necessary evil unfortunately.
GrayWizardx
Yeah - doesn't seem to work, nevermind :) Thanks for your answer :)
Annie
@GrayWizardx: This is of course possible. This would also generate the output document in the respective default namespace.
Tomalak
@Tomalak Can you provide an example for this? I couldn't get it to work..
Annie