【发布时间】:2017-06-09 11:08:11
【问题描述】:
我正在尝试使用某种循环在 LoopingNode 上进行 BizTalk 映射,如果 Cond1 为假,则创建 Type1。如果Cond1 为真,则创建Type2。它看起来像这样:
输入:
root
- LoopingNode
- id (string)
- Cond1 (bool)
输出:
root
- TargetNode
<Equivalent>
- Type1
- id (string)
- Type2
- id (string)
输出应该是这样的
<root>
<TargetNode type="Type2" id="a" />
<TargetNode type="Type1" id="q" />
</root>
我曾尝试使用 2 个表循环,将第 1 列作为门,但这不起作用。我最近的尝试是以 cond 为条件进行值映射。生成的xslt变成了这样:
<xsl:attribute name="xsi:type">
<xsl:value-of select="'ns0:Type1'" />
</xsl:attribute>
<xsl:if test="string($var:v6)='true'">
<xsl:variable name="var:v7" select="string(s1:Id/text())" />
<xsl:attribute name="id">
<xsl:value-of select="$var:v7" />
</xsl:attribute>
</xsl:if>
<xsl:attribute name="xsi:type">
<xsl:value-of select="'ns0:Type2'" />
</xsl:attribute>
<xsl:if test="string($var:v6)='false'">
<xsl:variable name="var:v10" select="string(s1:Id/text())" />
<xsl:attribute name="id">
<xsl:value-of select="$var:v10" />
</xsl:attribute>
</xsl:if>
由于xsl:if 仅围绕id-tag 而不是<xsl:attribute name="xsi:type"> 标签,因此该值将始终为Type2,因为它在xslt 中是最后一个。
我宁愿有一个非自定义的 xslt 解决方案,但也许这是不可能的。真正的问题比这复杂得多(大约 20 个属性、3 个等效类型和 2 个条件)。但是解决方案应该是一样的。
任何想法如何在等效节点上进行条件循环?
更新: 这是与我的问题相对应的架构(xsd):
<?xml version="1.0" encoding="utf-16"?>
<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns="http://demo.com/schema/" targetNamespace="http://demo.com/schema/" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="root" type ="Root">
</xs:element>
<xs:complexType name="Root">
<xs:sequence>
<xs:element name="TargetNode" type="TargetNode" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="TargetNode" abstract="true">
<xs:attribute name="id" type="xs:string" use="required" />
</xs:complexType>
<xs:complexType name="Type1">
<xs:complexContent>
<xs:extension base="TargetNode">
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Type2">
<xs:complexContent>
<xs:extension base="TargetNode">
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
【问题讨论】:
标签: xml xslt mapping biztalk biztalk-mapper