2014-01-27 53 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