2014-01-27 51 views
0

中分组项有没有办法采取看起来像这样的XML文件:的Biztalk:映射

<?xml version="1.0" encoding="utf-8"?> 
<spMyStoredProc xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo"> 
<StoredProcedureResultSet0> 
    <StoredProcedureResultSet0 xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo/spMyStoredProc"> 
     <Item>1</Item> 
     <Property>something</property> 
    </StoredProcedureResultSet0> 
    <StoredProcedureResultSet0 xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo/spMyStoredProc"> 
     <Item>2</Item> 
     <Property>something</property> 
    </StoredProcedureResultSet0> 
    <StoredProcedureResultSet0 xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo/spMyStoredProc"> 
     <Item>3</Item> 
     <Property>something</property> 
     <Group>1</Group> 
    </StoredProcedureResultSet0> 
    <StoredProcedureResultSet0 xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo/spMyStoredProc"> 
     <Item>4</Item> 
     <Property>something</property> 
     <Group>1</Group> 
    </StoredProcedureResultSet0> 
    <StoredProcedureResultSet0 xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo/spMyStoredProc"> 
     <Item>5</Item> 
     <Property>something</property> 
     <Group>2</Group> 
    </StoredProcedureResultSet0> 
    <StoredProcedureResultSet0 xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo/spMyStoredProc"> 
     <Item>6</Item> 
     <Property>something</property> 
     <Group>2</Group> 
    </StoredProcedureResultSet0> 
    </StoredProcedureResultSet0> 
    <ReturnValue>0</ReturnValue> 
</spMyStoredProc> 

出来的格式如下:

<MyRequests> 
    <Request> 
     <Item ID="1" Property="Something" /> 
    </Request> 
    <Request> 
     <Item ID="2" Property="Something" /> 
    </Request> 
    <Request GroupID="1"> 
     <Item ID="3" Property="Something" /> 
     <Item ID="4" Property="Something" /> 
    </Request> 
    <Request GroupID="2"> 
     <Item ID="5" Property="Something" /> 
     <Item ID="6" Property="Something" /> 
    </Request> 
</MyRequests> 

我亲近只是用从源模式到目的地的直接映射,但它不会将具有相同组ID的项组合在一起。

基本上,我能够得到没有functoid的是这样的:

<MyRequests> 
    <Request> 
     <Item ID="1" Property="Something" /> 
    </Request> 
    <Request> 
     <Item ID="2" Property="Something" /> 
    </Request> 
    <Request GroupID="1"> 
     <Item ID="3" Property="Something" /> 
    </Request> 
    <Request GroupID="1"> 
     <Item ID="4" Property="Something" /> 
    </Request> 
    <Request GroupID="2"> 
     <Item ID="5" Property="Something" /> 
    </Request> 
    <Request GroupID="2"> 
     <Item ID="6" Property="Something" /> 
    </Request> 
</MyRequests> 
+0

您显示的输入不是XML文档,而是XML片段,因此XSLT将无法解析它。它需要包装在一个顶层元素中。 – LarsH

+0

P.S.你在使用XSLT 1.0还是2.0?在2.0中,分组问题的答案通常要容易得多。 – LarsH

+0

更新了原始XML以显示原始文档的更接近的表示。由于我公司的“卫生处理”规则,只提前张贴了片段。 – SpaceCowboy74

回答

1

这听起来像XSLT 2.0 isn't supported in Biztalk,所以这个答案是关于XSLT 1.0。

假设你的XML输入文件是良好的,即包装在单个顶层元素...

对于这种分组问题的标准方法是Meunchian分组。例如参见https://stackoverflow.com/a/1929273/423105https://stackoverflow.com/a/2334224/423105。如果您在应用这些答案时遇到困难,请留下具体问题的评论。

+0

谢谢!我会仔细看看,看看我能想出什么。 – SpaceCowboy74

+1

@OP:关于Muenchian分组的另一个很好的解释,请参阅http://www.jenitennison.com/xslt/grouping/muenchian.html – LarsH

+0

我想我得到的分组大部分工作,但它只返回整数值。有无论如何接受空值或缺失作为有效值? – SpaceCowboy74