0

「Altova MapForce」マッピング ツールを使用しており、ノードからノードへマッピングしています。結果の xml (altova xslt プロセッサを使用) には、空でないノードはありません。結果の xml (biztalk xslt プロセッサを使用し、Altova Mapforce から生成された xsl を使用) は、空ではないノードを含みます。そのノードはソース上で空です。

私の目標は、ソース ノードを (Altova MapForce マッピング ツールを使用して) カスタム作成された XSLT に接続し、それをターゲットに接続することです。

これが私のコードです: in.xml - マップを実行するためのインスタンス入力 (空の id タグに注意してください: )

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Schema1">
  <id root="root_0" extension="extension_1" />
</ns0:Root>

Schema1.xsd - ソースおよびターゲット スキーマ

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://BizTalk_Server_Project1.Schema1" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://BizTalk_Server_Project1.Schema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="id">
          <xs:complexType>
            <xs:attribute name="root" type="xs:string" />
            <xs:attribute name="extension" type="xs:string" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

New.mfd - Altova マッピング ファイル

<?xml version="1.0" encoding="UTF-8"?>
<mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="19">
    <component name="defaultmap1" blackbox="0" uid="1" editable="1">
        <properties SelectedLanguage="xslt"/>
        <structure>
            <children>
                <component name="document" library="xml" uid="4" kind="14">
                    <properties/>
                    <view rbx="150" rby="200"/>
                    <data>
                        <root>
                            <header>
                                <namespaces>
                                    <namespace/>
                                    <namespace uid="http://BizTalk_Server_Project1.Schema1"/>
                                    <namespace uid="http://www.altova.com/mapforce"/>
                                </namespaces>
                            </header>
                            <entry name="FileInstance" ns="2" expanded="1">
                                <entry name="document" ns="2" expanded="1" casttotargettypemode="cast-in-subtree">
                                    <entry name="Root" ns="1" expanded="1">
                                        <entry name="id" expanded="1">
                                            <entry name="extension" type="attribute" outkey="4"/>
                                        </entry>
                                    </entry>
                                </entry>
                            </entry>
                        </root>
                        <document schema="Schema1.xsd" outputinstance="Schema1.xml" instanceroot="{http://BizTalk_Server_Project1.Schema1}Root"/>
                        <wsdl/>
                    </data>
                </component>
                <component name="document" library="xml" uid="5" kind="14">
                    <properties XSLTDefaultOutput="1"/>
                    <view ltx="593" rbx="743" rby="200"/>
                    <data>
                        <root>
                            <header>
                                <namespaces>
                                    <namespace/>
                                    <namespace uid="http://BizTalk_Server_Project1.Schema1"/>
                                    <namespace uid="http://www.altova.com/mapforce"/>
                                </namespaces>
                            </header>
                            <entry name="FileInstance" ns="2" expanded="1">
                                <entry name="document" ns="2" expanded="1" casttotargettypemode="cast-in-subtree">
                                    <entry name="Root" ns="1" expanded="1">
                                        <entry name="id" expanded="1">
                                            <entry name="extension" type="attribute" inpkey="5"/>
                                        </entry>
                                    </entry>
                                </entry>
                            </entry>
                        </root>
                        <document schema="Schema1.xsd" outputinstance="Schema1.xml" instanceroot="{http://BizTalk_Server_Project1.Schema1}Root"/>
                        <wsdl/>
                    </data>
                </component>
            </children>
            <graph directed="1">
                <edges/>
                <vertices>
                    <vertex vertexkey="4">
                        <edges>
                            <edge vertexkey="5" edgekey="6"/>
                        </edges>
                    </vertex>
                </vertices>
            </graph>
        </structure>
    </component>
</mapping>

Xsl.xsl - Altova Mapper によって生成された Xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://BizTalk_Server_Project1.Schema1" xmlns:agt="http://www.altova.com/Mapforce/agt" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="ns0 agt xs">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template name="agt:var2_MapToSchema1_function">
        <xsl:param name="par0"/>
        <xsl:attribute name="extension">
            <xsl:value-of select="string($par0/@extension)"/>
        </xsl:attribute>
    </xsl:template>
    <xsl:template match="/">
        <Root xmlns="http://BizTalk_Server_Project1.Schema1">
            <xsl:attribute name="xsi:schemaLocation" namespace="http://www.w3.org/2001/XMLSchema-instance">http://BizTalk_Server_Project1.Schema1 C:/Users/OhadAv/Desktop/ForAltova/Schema1.xsd</xsl:attribute>
            <id xmlns="">
                <xsl:for-each select="ns0:Root/id">
                    <xsl:variable name="var1_extension">
                        <xsl:if test="@extension">
                            <xsl:value-of select="'1'"/>
                        </xsl:if>
                    </xsl:variable>
                    <xsl:if test="string(boolean(string($var1_extension))) != 'false'">
                        <xsl:call-template name="agt:var2_MapToSchema1_function">
                            <xsl:with-param name="par0" select="."/>
                        </xsl:call-template>
                    </xsl:if>
                </xsl:for-each>
            </id>
        </Root>
    </xsl:template>
</xsl:stylesheet>

GeneratedByBizTalkMapperAfterXSLTmap.xml - マップに "Xsl.xsl" を使用した後の BizTalk マッパーの出力インスタンス (xml ファイルの編集時に生成された空でない id タグに注意してください:

<?xml version="1.0" encoding="utf-8"?>
<Root xsi:schemaLocation="http://BizTalk_Server_Project1.Schema1 C:/Users/OhadAv/Desktop/ForAltova/Schema1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://BizTalk_Server_Project1.Schema1">
  <id extension="extension_1" xmlns="">
  </id>
</Root>
4

1 に答える 1

0

Altova マッパーによって生成された xslt はかなり乱雑に見えます。例: 1 回限りの変数の使用、1 回だけ使用される呼び出しテンプレート、および次のような繰り返し変換string(boolean(string(

マップでどのマッピングを行う必要があるかについては、100% 明確ではありません。

root属性を完全に削除し、id欠落していても要素を提供する場合は、以下の xslt が機能します。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:ns0="http://BizTalk_Server_Project1.Schema1" 
                xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                exclude-result-prefixes="ns0 xs">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/ns0:Root">
        <Root xmlns="http://BizTalk_Server_Project1.Schema1">
            <xsl:element name="id">
                <xsl:for-each select="ns0:Root/id">
                    <xsl:if test="@extension">
                        <xsl:attribute name="extension">
                            <xsl:value-of select="string(@extension)"/>
                        </xsl:attribute>
                    </xsl:if>
                </xsl:for-each>
            </xsl:element>
        </Root>
    </xsl:template>
</xsl:stylesheet>

これにより、xmlns、不要なスキーマの場所などを含まない XML が次のように生成されます。

<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="http://BizTalk_Server_Project1.Schema1">
  <id extension="extension_1" />
</Root>

ただし、入力ノードに存在しない id 要素を完全に省略したい場合は、テンプレートを次のように変更します。

<xsl:template match="/ns0:Root">
    <Root xmlns="http://BizTalk_Server_Project1.Schema1">
        <xsl:if test="id">
            <xsl:element name="id">
                <xsl:attribute name="extension">
                    <xsl:value-of select="string(id/@extension)"/>
                </xsl:attribute>
            </xsl:element>
        </xsl:if>
    </Root>
</xsl:template>

どのマップ

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.Schema1">
</ns0:Root>

に:

<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="http://BizTalk_Server_Project1.Schema1" />
于 2012-09-05T16:35:24.313 に答える