XSLT and Namespaces

Hi,
I'm having problems getting XSLT to deal with namespaces and I'm not sure if it's a .NET thing or a stylesheet thing. With running XPath queries in .NET you need to specify a namespace manager, fine, done that, works a treat. But I don't see any property or method with the XslTransform class that allows a namespace manager to be specified. So question one, is there a way to specify a namespace manager with XslTransform class

If there isn't then could someone tell me what I'm doing wrong with the stylesheet.
<sonnet type="Shakespearean">
  <auth:author xmlns:auth="http://www.authors.com/">
    <last-name>Shakespeare</last-name>
    <first-name>William</first-name>
    <nationality>British</nationality>
    <year-of-birth>1564</year-of-birth>
    <year-of-death>1616</year-of-death>
  </auth:author>
</sonnet>

There's the xml.... the auth:author element is what I'm wanting to transform.

<xsl:stylesheet    version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:auth="http://www.authors.com/">

    <xsl:template match="auth:author">
        <xsl:text>Hello World!</xsl:text>
    </xsl:template>

    <xsl:template match="/">
        <xsl:apply-templates select="auth:author" />
    </xsl:template>

</xsl:stylesheet>

That's the stylesheet.... nothing gets produced, not even if I run the xml and stylesheet through SAXON. Anyone know what's wrong



Answer this question

XSLT and Namespaces

  • JDehart

    Doesn't matter fixed it. Does that happen to anyone else  as soon as you post for help you solve the problem.

    Basically the initial template that matched / is the root element, which is something above the document element (sonnet node) in the above xml.

    Here is the solution incase anyone else has this problem.

    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:auth="http://www.authors.com/">

     <xsl:template match="auth:author">
      <xsl:text>Hello World!</xsl:text>  
     </xsl:template>

     <xsl:template match="/sonnet">
      <xsl:apply-templates select="auth:author" />
     </xsl:template>

    </xsl:stylesheet>



  • XSLT and Namespaces