tags:

views:

1221

answers:

2

Hi,

I have an XML file that I am trying to transform via an XSL file. As soon as I add an non-blank xmlns attribute to the root element of my XSL, the transformation just brings me back blank data for everything. If I remove or blank out the xmlns attribute, I get back what I expect.

Can anyone tell me why this is happening so I can stop it!

Here's a bit of my XSL (with some parts omitted & replaced with ...):

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

  <xsl:import href="html_commonstructures.xsl"/>
  <xsl:output method="html"/>

  <xsl:template match="/">
    <div>
    <xsl:call-template name="ServiceStructure">
      <xsl:with-param name="structure" select="ServiceDescription" />
    </xsl:call-template>
    </div>
  </xsl:template>

  <xsl:template name="ServiceStructure">
    <xsl:param name="structure"/>
    <h3>
      <xsl:value-of select="$structure/DC.Title" /> (<xsl:value-of select="$structure/DC.Identifier" />)
    </h3>
    <!-- And so on -->
  </xsl:template>
</xsl:stylesheet>

* EDIT * Here is a snippet of what's in html_commonstructures:

<?xml version='1.0' encoding='UTF-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rxr="http://ilrt.org/discovery/2004/03/rxr/" xmlns:esd="http://www.esd.org.uk/standards"
    xmlns:core="http://www.govtalk.gov.uk/core" xmlns:n2="http://www.govtalk.gov.uk/metadata/egms"
    xmlns:apd="http://www.govtalk.gov.uk/people/AddressAndPersonalDetails"
    xmlns:con="http://www.govtalk.gov.uk/people/ContactTypes"
    xmlns:bs7666="http://www.govtalk.gov.uk/people/bs7666"&gt;

  <!-- A template for the ControlledListStructures -->
  <xsl:template name="ControlledListStructure">
    <xsl:param name="structure"/>

    <p class="controlledlist">
      <xsl:value-of select="$structure/text()" />
      <xsl:if test="$structure/@Id | $structure/@ConceptId | $structure/@ItemName | $structure/@ListName">
        <span class="metainfo">[
          <xsl:if test="$structure/@Id">
            ID: <xsl:value-of select="$structure/@Id" />;
          </xsl:if>
          <xsl:if test="$structure/@ConceptId">
            Concept ID: <xsl:value-of select="$structure/@ConceptId" />;
          </xsl:if> 
          <xsl:if test="$structure/@ItemName">
            Item Name: <xsl:value-of select="$structure/@ItemName" />;
          </xsl:if>
          <xsl:if test="$structure/@ListName">
            List Name: <xsl:value-of select="$structure/@ListName" />
          </xsl:if>
          ]
        </span>
      </xsl:if>
    </p>
  </xsl:template>
</xsl:stylesheet>
+4  A: 

Why do you add the xmlns namespace definition in the first place?

By adding the xmlns attribute you change the default namespace of your XSLT. You must adjust all expression to use the namespace of your input document then, i.e. add the namespace definition of your input document using a free prefix and replace e.g. the expression 'ServiceDesription' with 'myPrefix:SerciveDescription'.

0xA3
The XML I am trying to transform comes from a 3rd party so I don't have much control over the namespaces etc. Cheers for the input though - I'll see if I can rejig things at all to help.
Lee Theobald
+2  A: 

If you have a namespace on the XML document then you need to have the same namespace on the XSLT.

Andrew Hare