BizTalk Map Group Person by Key
BizTalk Map Group Person by Key
我现有的地图,根据类型和许多其他逻辑,使用地图中的 functoid 将一个人从源模式转换为一个人从目标模式。由于最近对目标模式进行了更改,我需要修改转换以使用键 (guid) 节点,以便我们可以对数据进行分组。
我想为 //Person*/[Key=same] 之类的东西实现一个内联 XSLT 脚本,但在 XSLT 上不确定。
示例输入:
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
当前示例输出:
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
示例所需输出,基于相同的键值:
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
当此 XSLT 1.0 解决方案时:
<xsl:key name="groups" match="Test/Person/PersonKey/Key/text()" use="."/>
<xsl:template match="/">
<xsl:apply-templates select="/Test" />
</xsl:template>
<xsl:template match="/Test">
<Test>
<xsl:for-each select="Person/PersonKey/Key/text()[generate-id()=generate-id(key('groups',.))]">
<PartnerParents>
<Father>
<xsl:for-each select="key('groups',.)">
<xsl:if test="../../../Name/Gender/text() = 'MALE'">
<Title>
<xsl:value-of select="../../../Name/title/text()" />
</Title>
<Gender>
<xsl:value-of select="../../../Name/Gender/text()" />
</Gender>
</xsl:if>
</xsl:for-each>
</Father>
<Mother>
<xsl:for-each select="key('groups',.)">
<xsl:if test="../../../Name/Gender/text() = 'FEMALE'" >
<Title>
<xsl:value-of select="../../../Name/title/text()" />
</Title>
<Gender>
<xsl:value-of select="../../../Name/Gender/text()" />
</Gender>
</xsl:if>
</xsl:for-each>
</Mother>
</PartnerParents >
</xsl:for-each>
</Test>
...应用于以下 XML:
<Test>
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
</Test>
...产生了想要的结果:
<Test>
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
</Test>
我现有的地图,根据类型和许多其他逻辑,使用地图中的 functoid 将一个人从源模式转换为一个人从目标模式。由于最近对目标模式进行了更改,我需要修改转换以使用键 (guid) 节点,以便我们可以对数据进行分组。
我想为 //Person*/[Key=same] 之类的东西实现一个内联 XSLT 脚本,但在 XSLT 上不确定。
示例输入:
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
...
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
当前示例输出:
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
示例所需输出,基于相同的键值:
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
当此 XSLT 1.0 解决方案时:
<xsl:key name="groups" match="Test/Person/PersonKey/Key/text()" use="."/>
<xsl:template match="/">
<xsl:apply-templates select="/Test" />
</xsl:template>
<xsl:template match="/Test">
<Test>
<xsl:for-each select="Person/PersonKey/Key/text()[generate-id()=generate-id(key('groups',.))]">
<PartnerParents>
<Father>
<xsl:for-each select="key('groups',.)">
<xsl:if test="../../../Name/Gender/text() = 'MALE'">
<Title>
<xsl:value-of select="../../../Name/title/text()" />
</Title>
<Gender>
<xsl:value-of select="../../../Name/Gender/text()" />
</Gender>
</xsl:if>
</xsl:for-each>
</Father>
<Mother>
<xsl:for-each select="key('groups',.)">
<xsl:if test="../../../Name/Gender/text() = 'FEMALE'" >
<Title>
<xsl:value-of select="../../../Name/title/text()" />
</Title>
<Gender>
<xsl:value-of select="../../../Name/Gender/text()" />
</Gender>
</xsl:if>
</xsl:for-each>
</Mother>
</PartnerParents >
</xsl:for-each>
</Test>
...应用于以下 XML:
<Test>
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec58</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsFarther</PersonType>
<Name>
<title>MR</title>
<Gender>MALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
<Person>
<PersonType>PartnerParentsMother</PersonType>
<Name>
<title>MRS</title>
<Gender>FEMALE</Gender>
</Name>
<Address/>
<PersonKey>
<Key>a1093c4a-7c53-4de5-ad30-cb4140aec59</Key>
<ParentKey/>
</PersonKey>
</Person>
</Test>
...产生了想要的结果:
<Test>
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
<PartnerParents>
<Father>
<Title>MR</Title>
<Gender>MALE</Gender>
</Father>
<Mother>
<Title>MRS</Title>
<Gender>FEMALE</Gender>
</Mother>
</PartnerParents>
</Test>