Topic: Any ideas about the exchange between this two document type !!

  Print this page

1.Any ideas about the exchange between this two document type !! Copy to clipboard
Posted by: Lynn
Posted on: 2005-03-13 15:27

hi,everyone

who can give me the any ideas or samples about the exchange between document A & B following?

My Email:lynnyu_cn@msn.com

it's urgent,thanks in advance!

A:

  <head>
    <messagetype>StudentScore</messagetype>
    <version>1.0</version>
    <item>
      <property>
        <name>id</name>
        <value>Jim</value>
      </property>
      <property>
        <name>age</name>
        <value>18</value>
      </property>
      <property>
        <name>score</name>
        <value>95</value>
      </property>
    </item>
    <item>
      <property>
        <name>id</name>
        <value>Jake</value>
      </property>
      <property>
        <name>age</name>
        <value>14</value>
      </property>
      <property>
        <name>score</name>
        <value>95</value>
      </property>
    </item>
    <item>
      <property>
        <name>id</name>
        <value>Kate</value>
      </property>
      <property>
        <name>age</name>
        <value>18</value>
      </property>
      <property>
        <name>score</name>
        <value>61</value>
      </property>
    </item>
    <item>
      <property>
        <name>id</name>
        <value>Tom</value>
      </property>
      <property>
        <name>age</name>
        <value>16</value>
      </property>
      <property>
        <name>score</name>
        <value>100</value>
      </property>
    </item>
  </head>

B:

  <message>
    <messagetype>StudentScore</messagetype>
    <version>1.0</version>
    <record>
      <id>Jim</id>
      <age>18</age>
      <score>95</score>
    </record>
    <record>
      <id>Jake</id>
      <age>14</age>
      <score>95</score>
    </record>
    <record>
      <id>Kate</id>
      <age>18</age>
      <score>61</score>
    </record>
    <record>
      <id>Tom</id>
      <age>16</age>
      <score>100</score>
    </record>
  </message>

2.Re:Any ideas about the exchange between this two document type !! [Re: Lynn] Copy to clipboard
Posted by: Jove
Posted on: 2005-03-13 16:07

用XSL, 这种转换器的实现有很多
下面给出从A->B 和B->A的xsl文件

A2B.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<message>
<messagetype>
<xsl:value-of select="head/messagetype"/>
</messagetype>
<version>
<xsl:value-of select="head/version"/>
</version>
<xsl:apply-templates select="head/item"/>
</message>
</xsl:template>
<xsl:template match="head/item">
<record>
<id>
<xsl:value-of select="property[name='id']/value"/>
</id>
<age>
<xsl:value-of select="property[name='age']/value"/>
</age>
<score>
<xsl:value-of select="property[name='score']/value"/>
</score>
</record>
</xsl:template>
</xsl:stylesheet>


B2A.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<head>
<messagetype>
<xsl:value-of select="message/messagetype"/>
</messagetype>
<version>
<xsl:value-of select="message/version"/>
</version>
<xsl:apply-templates select="message/record"/>
</head>
</xsl:template>
<xsl:template match="message/record">
<item>
<property>
<name>id</name>
<value>
<xsl:value-of select="id"/>
</value>
</property>
<property>
<name>age</name>
<value>
<xsl:value-of select="age"/>
</value>
</property>
<property>
<name>score</name>
<value>
<xsl:value-of select="score"/>
</value>
</property>
</item>
</xsl:template>
</xsl:stylesheet>


3.Re:Any ideas about the exchange between this two document type !! [Re: Lynn] Copy to clipboard
Posted by: Lynn
Posted on: 2005-03-13 16:42

Jove,thanks very much for your response,

but node like 'id','age','score' in document B should not be hard-coded,they should get from item/property/name.

<xsl:template match="head/item">
  <record>
    <id>id should not be hard-coded here,should get from item/property/name>

      <xsl:value-of select="property[name='id']/value"/>
    </id>
    <age>
      <xsl:value-of select="property[name='age']/value"/>
    </age>
    <score>
      <xsl:value-of select="property[name='score']/value"/>
    </score>
  </record>
</xsl:template>

4.Re:Any ideas about the exchange between this two document type !! [Re: Lynn] Copy to clipboard
Posted by: Jove
Posted on: 2005-03-13 17:36

well, you asked for it, you got it!

A2B.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/head">
<message>
<messagetype>
<xsl:value-of select="messagetype"/>
</messagetype>
<version>
<xsl:value-of select="version"/>
</version>
<xsl:apply-templates select="item"/>
</message>
</xsl:template>
<xsl:template match="item">
<record>
<xsl:apply-templates select="property"/>
</record>
</xsl:template>
<xsl:template match="property">
<xsl:element name="{name}">
<xsl:value-of select="value"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>


B2A.xsl
<?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="/message">
<head>
<messagetype>
<xsl:value-of select="messagetype"/>
</messagetype>
<version>
<xsl:value-of select="version"/>
</version>
<xsl:apply-templates select="record"/>
</head>
</xsl:template>
<xsl:template match="record">
<item>
<xsl:apply-templates/>
</item>
</xsl:template>
<xsl:template match="record/*">
<property>
<name>
<xsl:value-of select="name()"/>
</name>
<value>
<xsl:value-of select="."/>
</value>
</property>
</xsl:template>
</xsl:stylesheet>

5.Re:Any ideas about the exchange between this two document type !! [Re: Lynn] Copy to clipboard
Posted by: wishmaster
Posted on: 2005-03-14 16:26

it should be pretty easy and straightforward to deal with this in webMethods. you need to learn by reading more docs...

6.Re:Any ideas about the exchange between this two document type !! [Re: Lynn] Copy to clipboard
Posted by: Lynn
Posted on: 2005-03-14 22:04

Thanks for kind response.

yes , maybe it's so pretty easy to deal with this problem in webMethods after several days' reading or several months' development,and i absolutely believe that there is some way in webMethods.

but you know, for a new comer who faces to resolve this problem urgently want to ask for the straightforward solutions.

and i tried some builtin service like 'recordlistToRecord','recordToRecordlist','appendToRecordList',etc.also i have read the related docs,but i can't get the result i wanted.so i asked the help here.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923