0
votes

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-microsoft-com:xslt" exclude-result-prefixes="msxsl">
        <xsl:output method="xml" indent="yes"/>

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

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

Is there any way to modify my XSLT file to process the original XML without applying any changes to it? Thanks for help in advance!

1
Part that need to be fixed here is the XSLT, so it is important to show how your XSLT looks like (portion that has been posted so far is not at all enough)har07
Can you also say what error you actually get in the first instance? Thanks!Tim C
Added more XSLT. About an error: Visual Studio doesn't build a valid xml file after transformation. It inserts only plain text without tags etc.Trinadsatiy
You obviously have a namespace issue - look it up.michael.hor257k

1 Answers

0
votes

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.