xsl-list
[Top] [All Lists]

[xsl] Doesn't see elements when using namespaces

2006-08-17 05:07:54
I am trying to use a very simple XSLT to convert an XML file into CSV
(Comma Separated Values).  However, I'm having difficulties which seems
to be due to the namespaces.  Using XML Spy 5.4, it never finds any
<CodingNoticesP6P6B> elements to process.  If I remove all the
namespaces and "ns0:" prefixes in the XML and XSL files, then it works
fine.

Here is a simplified XML file:

<?xml version="1.0" encoding="utf-8"?>
<ns0:DPSdata
xmlns:ns0="http://www.govtalk.gov.uk/taxation/DPSwrapper/1";>
  <ns0:DataType>P6</ns0:DataType>
  <CodingNoticesP6P6B
        xmlns="http://www.govtalk.gov.uk/taxation/CodingNoticesP6P6B/2";
        xmlns:gt="http://www.govtalk.gov.uk/CM/core";
        xmlns:gms="http://www.govtalk.gov.uk/CM/gms-xs";
        IssueDate="2005-09-01">
    <Name>Alan Brown</Name>
    <TaxCode>123L</TaxCode>
  </CodingNoticesP6P6B>
  <CodingNoticesP6P6B
        xmlns="http://www.govtalk.gov.uk/taxation/CodingNoticesP6P6B/2";
        xmlns:gt="http://www.govtalk.gov.uk/CM/core";
        xmlns:gms="http://www.govtalk.gov.uk/CM/gms-xs";
        IssueDate="2005-09-01">
    <Name>Julie Green</Name>
    <TaxCode>345L</TaxCode>
  </CodingNoticesP6P6B>
</ns0:DPSdata>


Here is my XSL file:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0"
  xmlns:ns0="http://www.govtalk.gov.uk/taxation/DPSwrapper/1";>
<xsl:output method="text" media-type="text/xml"
omit-xml-declaration="yes" encoding="UTF-8"/>

  <!-- This contains the character used as the end of line delimiter.
-->
  <xsl:variable name="CR" select=" '&#13;' "/>

  <!-- Start at the top level -->
  <xsl:template match="/">
    <xsl:apply-templates select="//ns0:DPSdata"/>
  </xsl:template>

  <!-- The header details -->
  <xsl:template match="ns0:DPSdata">
    <xsl:text>1,</xsl:text>
    <xsl:value-of select="ns0:DataType"/>
    <xsl:value-of select="$CR"/>
    <xsl:apply-templates select="//CodingNoticesP6P6B"/>
  </xsl:template>

  <!--- Process a P6/P6B -->
  <xsl:template match="CodingNoticesP6P6B">
    <xsl:call-template name="ExtractDetails"/>  
  </xsl:template>

  <!-- Extract all the details for the P6/P9 -->
  <xsl:template name="ExtractDetails">
    <xsl:text>2,</xsl:text>
    <xsl:value-of select="@IssueDate"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="Name"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select="TaxCode"/>
    <xsl:value-of select="$CR"/>
  </xsl:template>
        
</xsl:stylesheet>

Can anyone see what I'm doing wrong?

Thanks in anticipation.

Colin Simpson
************************************************************************

 Blue Arrow is official sponsor and recruitment partner of Team GB, the 
 British Olympic Association and OPEN, the Olympic and Paralympic 
 Employment Network.
 
 Your company can become a member of OPEN - the Olympic and Paralympic 
 Employment Network today, for free - visit www.bluearrow.co.uk/OPEN
 
 Find out more about all Blue Arrow recruitment solutions - visit 
 www.bluearrow.co.uk
 
************************************************************************


************************************************************************

This email and any files transmitted with it are confidential and 
intended solely for the use of the individual or entity to whom they
are addressed.  If you have received this email in error please notify 
the system manager.

************************************************************************

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>