views:

359

answers:

2

I have some XML that I am trying to transform to HTML using XSLT, but I can't get it to work for the life of me. Can someone tell me what I am doing wrong?

XML

<ArrayOfBrokerage xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.test.com/"&gt;
<Brokerage>
 <BrokerageID>91</BrokerageID>
 <LastYodleeUpdate>0001-01-01T00:00:00</LastYodleeUpdate>
 <Name>E*TRADE</Name>
 <Validation i:nil="true" />
 <Username>PersonalTradingTesting</Username>
</Brokerage></ArrayOfBrokerage>

XSLT

<xsl:stylesheet version="1.0" xmlns="http://www.test.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xslFormatting="urn:xslFormatting">
<xsl:output method="html" indent="no"/>

<xsl:template match="/ArrayOfBrokerage">
 <xsl:for-each select="Brokerage">
  Test
 </xsl:for-each>
</xsl:template>

A: 

How do you execute the transformation? Maybe you fotgot to link the xslt stylesheet to xml document using

<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>

at the begining of xml document. More explanation here

Steve
I'm not sure what you mean by this. I'm actually not doing a transform on an XML file but rather serializing a business object using the DataContractSerializer and specifying the namespace in the DataContract of the object.
Chris
+2  A: 

Definitely need a closing tag as @Janek mentions. But you need to provide a namespace prefix in your xslt for the elements you are transforming. For some reason (at least in a Java JAXP parser) you can't simply declare a default namespace. This worked for me:

<xsl:stylesheet version="1.0" xmlns:t="http://www.test.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xslFormatting="urn:xslFormatting">
<xsl:output method="html" indent="no"/>

<xsl:template match="/t:ArrayOfBrokerage">
    <xsl:for-each select="t:Brokerage">
            Test
    </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

This will catch everything that is namespaced in your XML doc.

Andy Gherna
This worked for me too in testing (running XSLT debug in Visual Studio 2008)
Murph
This did the trick. I had tried this with the combination of exclude-result-prefixes="t" because I thought it would allow me to not have to tack on t: before each node. Is there any way to avoid having to do this?
Chris
I don't think there is.
Andy Gherna
You could match elements using the local-name(), for instance: template match="/*[local-name()='ArrayOfBrokerage']"
Mads Hansen