java works, but xmlspy seems broken and some xsd and space questions?

Discussion in 'XML' started by Ray Tayek, Nov 29, 2003.

  1. Ray Tayek

    Ray Tayek Guest

    hi, trying to convert some csv files into xsml and pulling a few hairs
    out :(. using the files below. a java program will parse the csv and
    take care of strange names and notes that line breaks in them.

    eventiually i want to generate the xslt from a xml file (all the files
    and java code are at http://tayek.com/~ray/spy1/).

    the java code (1.4) does the right thing (it just does the
    transformation). xmlspy seems really broken when i hit f10 to run the
    inputDocument.xml through the sampleT1.xslt (i am trying the enterprize
    version). even putting in <xsl:text>
    </xsl:text>", the spy just
    seems to ignore it (but the java does something reasonable).

    also, i have text in my xslt like <outputRow> and later </outputRow>.
    this is one of the things what xmlspy seems to discard.

    the field names from the csv (called inputFieldName in the xml) can
    contain some screwball stuff line ' and ", so i made these text
    elements an xs:string. they can not contain any other xml (i.e. no
    <...>). so is xs:string the right way to do this? or should one use
    normalized string?

    what does nillable mean or do? - it lets things be empty? is there a way
    to force things to have just attributes and no content?

    there should be *no* text or any other markup (ignoring specal for the
    moment) anywhere except for inside an inputField or an inputFieldName.
    is there a way to tell the schema thia?

    eventually, i want to use the a file like inputDocumentMap.xml to
    generate the xslt using xslt (i am doing this now in java, but with a
    different inputDocumentMap.xml file).

    any pointers would be appreciated.

    thanks


    file inputDocument.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSPY v2004 rel. 3 (http://www.xmlspy.com) by Ray
    Tayek (Freightgate) -->
    <!--Sample XML file generated by XMLSPY v2004 rel. 3 U
    (http://www.xmlspy.com)-->
    <inputDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="H:\java\projects\spy1\spy\inputDocument.xsd">
    <special>Text</special>
    <header>
    <inputFieldName>copy1</inputFieldName>
    <inputFieldName>remove1</inputFieldName>
    <inputFieldName>rename1</inputFieldName>
    <inputFieldName>special1</inputFieldName>
    <inputFieldName>special2</inputFieldName>
    </header>
    <inputRecords>
    <inputRecord>
    <inputField>copy1Value1</inputField>
    <inputField>remove1Value1</inputField>
    <inputField>rename1Value1</inputField>
    <inputField>special1Value1</inputField>
    <inputField>special2Value1</inputField>
    </inputRecord>
    <inputRecord>
    <inputField>copy1Value2</inputField>
    <inputField>remove1Value2</inputField>
    <inputField>rename1Value2</inputField>
    <inputField>special1Value2</inputField>
    <inputField>special2Value2</inputField>
    </inputRecord>
    </inputRecords>
    </inputDocument>

    file inputDocument.xsd:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by Ray
    Tayek (Freightgate) -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="inputDocument">
    <xs:annotation>
    <xs:documentation>input csv converted to xml</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:sequence>
    <xs:element name="special" type="xs:anyType" minOccurs="0"/>
    <xs:element name="header" minOccurs="0">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="inputFieldName" type="xs:string"
    nillable="false" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="inputRecords" minOccurs="0">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="inputRecord" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="inputField" type="xs:string"
    nillable="false" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>


    files sampleT.xslt:

    <?xml version="1.0" encoding="UTF-8"?>
    <?xmlspysamplexml inputDocument.xml?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!--<xsl:strip-space elements="*"/>-->
    <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/inputDocument">
    <outputDocument>
    <xsl:apply-templates/>
    </outputDocument>
    </xsl:template>
    <xsl:template match="/inputDocument/special">
    </xsl:template>
    <xsl:template match="/inputDocument/header">
    </xsl:template>
    <xsl:template match="/inputDocument/inputRecords">
    <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="/inputDocument/inputRecords/inputRecord">
    <!--<xsl:for-each select="child::*[position()=4 or position()=5]">
    works -->
    <xsl:for-each select="child::*">
    <xsl:if test="position()=4">
    <xsl:call-template name="generateOutputRecord">
    <xsl:with-param name="value1" select="'new1ValueFromSpecial1Name'"/>
    <xsl:with-param name="value2" select="'new2ValueFromSpecial1Name'"/>
    </xsl:call-template>
    </xsl:if>
    <xsl:if test="position()=5">
    <xsl:call-template name="generateOutputRecord">
    <xsl:with-param name="value1" select="'new1ValueFromSpecial2Name'"/>
    <xsl:with-param name="value2" select="'new2ValueFromSpecial2Name'"/>
    </xsl:call-template>
    </xsl:if>
    </xsl:for-each>
    </xsl:template>
    <xsl:template name="generateOutputRecord">
    <xsl:param name="value1" select="defaultValue1"/>
    <xsl:param name="value2" select="defaultValue2"/>
    <outputRow>
    <inputRecordSequenceNumber>
    <xsl:number count="inputRecord"/>
    </inputRecordSequenceNumber>
    <xsl:for-each select="../*">
    <xsl:call-template name="processField"/>
    </xsl:for-each>
    <xsl:call-template name="addNewFields">
    <xsl:with-param name="xvalue1" select="$value1"/>
    <xsl:with-param name="xvalue2" select="$value2"/>
    </xsl:call-template>
    </outputRow>
    </xsl:template>
    <xsl:template name="addNewFields">
    <xsl:param name="xvalue1" select="defaultValue1"/>
    <xsl:param name="xvalue2" select="defaultValue2"/>
    <xsl:element name="new1">
    <xsl:value-of select="$xvalue1"/>
    </xsl:element>
    <xsl:element name="new2">
    <xsl:value-of select="$xvalue2"/>
    </xsl:element>
    <xsl:element name="new3">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:template>
    <xsl:template name="processField">
    <xsl:choose>
    <xsl:when test="position()=4"/>
    <xsl:when test="position()=5"/>
    <xsl:when test="position()=2"/>
    <xsl:when test="position()=3">
    <xsl:element name="renamed1">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:when>
    <xsl:when test="position()=1">
    <xsl:element name="{/inputDocument/header/inputFieldName[1]}">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:when>
    <xsl:eek:therwise>
    <xsl:element name="{name()}">
    <xsl:value-of select="."/>
    </xsl:element>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>
    <!--
    -->
    </xsl:stylesheet>

    output from spy:

    1 copy1Value1 rename1Value1 new1ValueFromSpecial1Name
    new2ValueFromSpecial1Name special1Value1 1 copy1Value1 rename1Value1
    new1ValueFromSpecial2Name new2ValueFromSpecial2Name special2Value1 2
    copy1Value2 rename1Value2 new1ValueFromSpecial1Name
    new2ValueFromSpecial1Name special1Value2 2 copy1Value2 rename1Value2
    new1ValueFromSpecial2Name new2ValueFromSpecial2Name special2Value2

    output from java program: file outputDocument_.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <outputDocument>
    <outputRow>
    <inputRecordSequenceNumber>1</inputRecordSequenceNumber>
    <copy1>copy1Value1</copy1>
    <renamed1>rename1Value1</renamed1>
    <new1>new1ValueFromSpecial1Name</new1>
    <new2>new2ValueFromSpecial1Name</new2>
    <new3>special1Value1</new3>
    </outputRow>
    <outputRow>
    <inputRecordSequenceNumber>1</inputRecordSequenceNumber>
    <copy1>copy1Value1</copy1>
    <renamed1>rename1Value1</renamed1>
    <new1>new1ValueFromSpecial2Name</new1>
    <new2>new2ValueFromSpecial2Name</new2>
    <new3>special2Value1</new3>
    </outputRow>
    <outputRow>
    <inputRecordSequenceNumber>2</inputRecordSequenceNumber>
    <copy1>copy1Value2</copy1>
    <renamed1>rename1Value2</renamed1>
    <new1>new1ValueFromSpecial1Name</new1>
    <new2>new2ValueFromSpecial1Name</new2>
    <new3>special1Value2</new3>
    </outputRow>
    <outputRow>
    <inputRecordSequenceNumber>2</inputRecordSequenceNumber>
    <copy1>copy1Value2</copy1>
    <renamed1>rename1Value2</renamed1>
    <new1>new1ValueFromSpecial2Name</new1>
    <new2>new2ValueFromSpecial2Name</new2>
    <new3>special2Value2</new3>
    </outputRow>
    </outputDocument>

    inputDocumentMap.xml file

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSPY v2004 rel. 3 (http://www.xmlspy.com) by Ray
    Tayek (Freightgate) -->
    <!--Sample XML file generated by XMLSPY v2004 rel. 3 U
    (http://www.xmlspy.com)-->
    <inputDocumentMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="H:\java\projects\spy1\spy\inputDocumentMap.xsd">
    <inputFieldMap>
    <inputFieldname>copy1</inputFieldname>
    <map>
    <from>oldValue1</from>
    <to>newValue1</to>
    </map>
    <map>
    <from>oldValue2</from>
    <to>newValue2</to>
    </map>
    </inputFieldMap>
    <inputFieldMap delete="true">
    <inputFieldname>remove1</inputFieldname>
    </inputFieldMap>
    <inputFieldMap>
    <inputFieldname outputFieldName="renamed1">rename1</inputFieldname>
    </inputFieldMap>
    <inputFieldMap delete="true">
    <inputFieldname>special1</inputFieldname>
    <generate outputFieldName="new1">new1ValueFromSpecial1Name</generate>
    <generate outputFieldName="new2">new2ValueFromSpecial1Name</generate>
    <generate outputFieldName="new3" copyOriginalValue="true">will be
    ignored</generate>
    </inputFieldMap>
    <inputFieldMap delete="true">
    <inputFieldname>special2</inputFieldname>
    <generate outputFieldName="new1">new1ValueFromSpecial2Name</generate>
    <generate outputFieldName="new2">new2ValueFromSpecial2Name</generate>
    <generate outputFieldName="new3" copyOriginalValue="true">will be
    ignored</generate>
    </inputFieldMap>
    </inputDocumentMap>


    inputDocumetMap.xsd file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSPY v2004 rel. 3 U (http://www.xmlspy.com) by Ray
    Tayek (Freightgate) -->
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="inputDocumentMap">
    <xs:annotation>
    <xs:documentation>Comment describing your root element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:sequence>
    <xs:element name="inputFieldMap" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="inputFieldname" nillable="false">
    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base="xs:string">
    <xs:attribute name="outputFieldName" type="xs:Name"
    use="optional"/>
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>
    </xs:element>
    <xs:element name="map" nillable="false" minOccurs="0"
    maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="from" type="xs:string" nillable="false"/>
    <xs:element name="to" type="xs:string" nillable="false"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="generate" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base="xs:string">
    <xs:attribute name="outputFieldName" type="xs:string"
    use="required"/>
    <xs:attribute name="copyOriginalValue" type="xs:boolean"
    use="optional" default="false"/>
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    <xs:attribute name="delete" type="xs:boolean" use="optional"
    default="false"/>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    Ray Tayek, Nov 29, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Altova Announcements
    Replies:
    0
    Views:
    641
    Altova Announcements
    May 25, 2004
  2. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,863
    Bryan Bullard
    Jul 11, 2003
  3. Christian Seberino
    Replies:
    21
    Views:
    1,621
    Stephen Horne
    Oct 27, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    978
    Steve Lamb
    Oct 23, 2003
  5. KaR
    Replies:
    0
    Views:
    651
Loading...

Share This Page