Support > Import and export function utilization guide (R7) > Correspondence when changing model definition
ja | en

Wagby provides a mechanism that can absorb this when the model item definition is changed before and after data migration. Here I will explain how to do it.

In import processing by Wagby, conversion processing called XSLT is performed for each processing. This conversion file is Importxslfilename attribute of directory elementIt is specified in.Standard corresponds to the following processing.

  • If a value is not set for a mandatory item, set an alternative value.

However, for the following changesRespond manuallyit is necessary.

  • When the type of the item is changed
  • When the item name (English) has been changed
  • When adding a primary key or unique item

Normally, it is cumbersome to migrate data that has occurred such changes.However, since Wagby allows you to specify individual rules for import in the form of XSLT, you can automate many operations (by writing additional rules).Before trying to change all the data, please consider whether it can not describe the rule by XSLT.

Since the explanation about the format of XSLT is beyond the scope of this guide, we omit it.Here, we will explain it using a specific example.

You can also change XML data directly using other development languages ​​without using XSLT introduced on this page.

For example, you change the type of an item from "character string" to "number". At this time, if there is a non-numeric character string in the value of the item, a reading error will result, so we will describe the processing to ignore or convert such data in XSLT.

Example: Since item age is changed from character string to numeric type, it is set to ignore data other than numerical value

Original content:

<xsl:template match="age">
  <age>
    <xsl:value-of select="."/>
  </age>
</xsl:template>

Revised contents:

<xsl:template match="age">
  <age>
    <xsl:if test="number(.) >= 0">
      <xsl:value-of select="."/>
    </xsl:if>
  </age>
</xsl:template>

Example: Since item job was changed from character string to model reference, it converts the original character string to code value.

Original content:

<xsl:template match="job">
  <job>
    <xsl:value-of select="."/>
  </job>
</xsl:template>

Revised contents:

<xsl:template match="job">
  <job>
    <xsl:choose>
      <xsl:when test="text() = '学生'">
        <xsl:text>1</xsl:text>
      </xsl:when>
      <xsl:when test="text() = '会社員'">
        <xsl:text>2</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>-1</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </job>
</xsl:template>

Example: I want to convert "yyyy / MM / dd" to "yyyy-MM-dd" about the notation contents of item publishdate.

Original content:

<xsl:template match="publishdate">
  <publishdate>
    <xsl:value-of select="."/>
  </publishdate>
</xsl:template>

Revised contents:

<xsl:template match="publishdate">
  <publishdate>
    <xsl:choose>
      <xsl:when test='contains(text(),"/")'>
        <xsl:value-of
          select='substring-before(text(),"/")'/>
            -<xsl:value-of
              select='substring-before(substring-after(
                text(),"/"),"/")'/>
                  -<xsl:value-of select='substring-after(
                    substring-after(text(),"/"),"/")'/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select='text()'/>
      </xsl:otherwise>
    </xsl:choose>
  </publishdate>
</xsl:element>

For example, the item name (English) has been changed from "name" to "customername".In the automatically generated conversion XSL, since such a semantic conversion can not be interpreted, it manually modifies (converts XSL file) and maps it to the correct item.

Example: Change the item name from "name" to "customername".

Original content:

<xsl:template match="name">
  <name>
    <xsl:value-of select="."/>
  </name>
</xsl:template>

Revised contents:

<xsl:template match="name">
  <customername>
    <xsl:value-of select="."/>
  </customername>
</xsl:template>

It is necessary to pay attention so that the value of the added primary key or unique item does not overlap. In this case, however, it may be better to directly change the target data, not XSL conversion.

The first design was defined as "staff 1" and "staff 2", but this is the case to integrate this into "person in charge" (repetition item).

Suppose you exported the original model with the following XML file:

<customer>
<id>1000</id>
<name1>山田</name1>
<name2>佐藤</name2>
</customer>

We will convert this to XML and import it to the new model side.

<customer>
<id>1000</id>
<name>山田</name>
<name>佐藤</name>
</customer>

The modified XSLT file is as follows.

...(中略)...
<xsl:template match="/*">
  <customer>
    <xsl:choose>
    <xsl:when test="id">
      <xsl:apply-templates select="id[1]"/>
    </xsl:when>
    <xsl:otherwise>
      <id>-1</id>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates select="name"/>
    <xsl:apply-templates select="name1"/><!-- 追加 -->
    <xsl:apply-templates select="name2"/><!-- 追加 -->
  </customer>
</xsl:template>

<xsl:template match="id">
  <id>
    <xsl:value-of select="."/>
  </id>
</xsl:template>

<xsl:template match="name">
  <name>
    <xsl:value-of select="."/>
  </name>
</xsl:template>

<xsl:template match="name1"><!-- 追加 -->
  <name>
    <xsl:value-of select="."/>
  </name>
</xsl:template>

<xsl:template match="name2"><!-- 追加 -->
  <name>
    <xsl:value-of select="."/>
  </name>
</xsl:template>

The first design was defined as "staff 1" and "staff 2", but this is when you want to integrate this into "person in charge" (item in repetitive container).

The definition of the original model is as follows.

Item name (Japanese) Item name (English) Item type Primary key repetition
ID address_id integer
Person in charge 1 con_member_id String
Person in charge 2 con_member_id2 String

Suppose that the XML file when exporting with this model definition is as follows.

<address>
<address_id>1000</address_id>
<con_member_id>田中</con_member_id>
<con_member_id2>鈴木</con_member_id2>
</address>

We will convert this to the following model definition.

Item name (Japanese) Item name (English) Item type Primary key repetition
ID address_id integer
Report report (Container of repetitive items)
Report ID report/id1 (ID for repeated item container)
Person in charge report/syain String
Notes report/memo String
Notes report/date1 date

Specifically, it converts it to the following XML and then imports it to the new model side.

<address>
<address_id>1000</address_id>
<report>
 <reportjshid>0</reportjshid>
 <id1>1</id1>
 <syain>田中</syain>
</report>
<report>
 <reportjshid>1</reportjshid>
 <id1>2</id1>
 <syain>鈴木</syain>
</report>
</address>

The item "reportjshid" is used internally by Wagby.It is not provided in the Wagby definition file, but it is necessary at the time of import.

The modified XSLT file is as follows.

...(中略)...
<xsl:template match="/*">
  <address>
    <xsl:choose>
    <xsl:when test="address_id">
      <xsl:apply-templates select="address_id[1]"/>
    </xsl:when>
    <xsl:otherwise>
      <address_id>-1</address_id>
    </xsl:otherwise>
    </xsl:choose>

    <xsl:apply-templates
         select="report | con_member_id | con_member_id2"/>

  </address>
</xsl:template>

<xsl:template match="address_id">
  <address_id>
    <xsl:value-of select="."/>
  </address_id>
</xsl:template>

<xsl:template match="report">
  <report>
    <xsl:choose>
    <xsl:when test="/*/address_id">
      <xsl:apply-templates select="/*/address_id[1]"/>
    </xsl:when>
    <xsl:otherwise>
      <address_id>-1</address_id>
    </xsl:otherwise>
    </xsl:choose>

    <reportjshid>
        <xsl:value-of select="position()-1"/>
    </reportjshid>

    <xsl:apply-templates select="id[1]"/>

    <xsl:apply-templates select="syain[1]"/>

    <xsl:apply-templates select="memo[1]"/>

    <xsl:apply-templates select="date1[1]"/>

  </report>

</xsl:template>

<xsl:template match="report/id">
  <id>
    <xsl:value-of select="."/>
  </id>
</xsl:template>

<xsl:template match="report/syain">
  <syain>
    <xsl:value-of select="."/>
  </syain>
</xsl:template>

<xsl:template match="report/memo">
  <memo>
    <xsl:value-of select="."/>
  </memo>
</xsl:template>

<xsl:template match="report/date1">
  <date1>
    <xsl:value-of select="."/>
  </date1>
</xsl:template>

<xsl:template match="con_member_id | con_member_id2">
  <report>
    <xsl:choose>
    <xsl:when test="/*/address_id">
      <xsl:apply-templates select="/*/address_id[1]"/>
    </xsl:when>
    <xsl:otherwise>
      <address_id>-1</address_id>
    </xsl:otherwise>
    </xsl:choose>

    <reportjshid>
        <xsl:value-of select="position()-1"/>
    </reportjshid>

    <id1>
        <xsl:value-of select="position()"/>
    </id1>

    <syain>
        <xsl:value-of select="text()"/>
    </syain>
  </report>
</xsl:template>

"Import data of classic calendar view into modern calendar viewUsing the migration tool described in "XSLT file that can load classic calendar format data in modern calendar format is prepared.

Here we will model the schedule.I will explain with the next item as an example.

Usage items Classic modern
date sdate -
Start time stime -
End time etime -
Start date and time - begindate (= sdate + stime)
End date and time - enddate (= sdate + etime)

XSLT file

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>

<xsl:template match="/*">
  <schedule>
...
    <xsl:apply-templates select="sdate[1]"/> <!-- クラシック形式の日付項目 -->
...
  </schedule>
</xsl:template>

<xsl:template match="sdate"> <!-- クラシック形式の日付項目 -->
  <begindate> <!-- モダン形式の開始日時 -->
    <xsl:choose>
      <xsl:when test='contains(text(),"T")'>
        <xsl:value-of select='substring-before(text(),"T")'/>
        <xsl:text>T</xsl:text>
        <xsl:apply-templates select="/*/stime[1]"/> <!-- クラシック形式の開始時刻 -->
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select='text()'/>
      </xsl:otherwise>
    </xsl:choose>
  </begindate>

  <enddate> <!-- モダン形式の終了日時 -->
    <xsl:choose>
      <xsl:when test='contains(text(),"T")'>
        <xsl:value-of select='substring-before(text(),"T")'/>
        <xsl:text>T</xsl:text>
        <xsl:apply-templates select="/*/etime[1]"/> <!-- クラシック形式の終了時刻 -->
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select='text()'/>
      </xsl:otherwise>
    </xsl:choose>
  </enddate>
</xsl:template>

<xsl:template match="stime | etime">
  <xsl:choose>
    <xsl:when test='contains(text(),"T")'>
      <xsl:value-of select='substring-after(text(),"T")'/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select='text()'/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
  • Prepare the "start date and time" item in modern format from the "date" + "start time" item in classic format.
  • Prepare "end date and time" item of modern format from "date" + "end time" item in classic format.
  • Since the date is internally "yyyy - MM - ddThh: mm: ss + 09: 00", the date part and the time part are judged before and after the character 'T'.