Trinadsatiy February 2016

XPATH, XSLT: transformation failed due to incorrect schema

I have incoming xml that I need to transform. The xml begins:

        <?xml version="1.0" encoding="utf-8"?>
    <ExportDataSet xmlns="http://tempuri.org/ExportDataSet.xsd">
        <xs:schema id="ExportDataSet" targetNamespace="http://tempuri.org/ExportDataSet.xsd" xmlns:mstns="http://tempuri.org/ExportDataSet.xsd" xmlns="http://tempuri.org/ExportDataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
            <xs:element name="ExportDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:element name="Document">

Trying to transform this xml I get an error. I found that transformation completes successfully if the first scheme is changed to look like:

<?xml version="1.0" encoding="utf-8"?>
<ExportDataSet xmlns:d2p1="http://www.w3.org/2001/XMLSchema">
    <xs:schema id="ExportDataSet" targetNamespace="http://tempuri.org/ExportDataSet.xsd" xmlns:mstns="http://tempuri.org/ExportDataSet.xsd" xmlns="http://tempuri.org/ExportDataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
        <xs:element name="ExportDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">

So in the beginning xmlns="http://tempuri.org/ExportDataSet.xsd" is changed to xmlns:d2p1="http://www.w3.org/2001/XMLSchema" I'm using a standart XSLT file generated by Visual Studio. in begins with:

        <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    xmlns:msxsl="urn:schemas-micro        

Answers


Trinadsatiy February 2016

So thanks to everyone, I had to declare new schema http://tempuri.org/ExportDataSet.xsd using a prefix and than use that prefix with all nodes:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    
                xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
                xmlns:tmp="http://tempuri.org/ExportDataSet.xsd">
    <xsl:output method="xml" indent="yes"/>

  <xsl:template match="tmp:ExportDataSet" >
    <xsl:element name="Declarations">
      <xsl:apply-templates select="tmp:Document" />
    </xsl:element>
  </xsl:template>

  <xsl:template match="tmp:Document">

Now transformation works fine.

Post Status

Asked in February 2016
Viewed 1,093 times
Voted 13
Answered 1 times

Search




Leave an answer