2013-06-28 123 views
0

我有這樣的項進行輸入XML轉型XSLT遞歸嵌套模板

<BusinessInteractionTypes> 
    <BusinessInteractionType> 
    <TypeId>123</TypeId> 
    <Name>Foo</Name> 
    <Description>XSLT</Description> 
    </BusinessInteractionType> 
    ...a lot BusinessInteractionType Elements 
</BusinessInteractionTypes> 

但是有很多的轉變(向SOA的情況下),我需要轉換使用XSLT此輸入:

<businessInteractionTypes> 
    <businessInteractionType> 
    <BusinessInteractionType> <!-- Just first input node --> 
    <TypeId/> 
    </BusinessInteractionType> 
    </businessInteractionType> 
    <businessInteractionTypeHas> <!-- Recursive interaction began --> 
    <businessInteractionType> 
     <BusinessInteractionType> 
     <TypeId /> 
     </BusinessInteractionType> 

     <businessInteractionTypeHas> 
     ... recursive 
    </businessInteractionType> 
    </businessInteractionTypeHas> 
</businessInteractionTypes> 
+0

這不是完全清楚的輸入和輸出是如何關聯。您沒有在輸入中包含足夠的內容以查看輸出結果如何。 –

+0

Jim感謝您的關注,我解決了這個問題,很快我會在這裏發佈解決方案 – user902870

回答

0

SRS時,我解決這個問題......遵循 感謝所有

<?xml version="1.0" encoding="UTF-8"?> 

<xsl:template match="cus:BusinessInteractionType"> 
    <xsl:call-template name="Master"> 
     <xsl:with-param name="nodeD" select="bus1:BusinessInteractionType"/> 
    </xsl:call-template> 
</xsl:template> 

<xsl:template name="Master"> 
    <xsl:param name="nodeD" select="bus1:BusinessInteractionType"/> 

    <cas:businessInteractionTypes> 
     <cas:businessInteractionType> 
      <xsl:if test="bus1:BusinessInteractionType[position() = 1]"> 
       <bus3:BusinessInteractionType> 
        <bus1:TypeId> 
         <xsl:value-of select="//bus1:TypeId"/> 
        </bus1:TypeId> 
       </bus3:BusinessInteractionType> 
      </xsl:if> 
      <xsl:call-template name="MasterNested"> 
       <xsl:with-param name="current_node" select="bus1:BusinessInteractionType[position()>1]"/> 
      </xsl:call-template> 
     </cas:businessInteractionType>  
    </cas:businessInteractionTypes> 
</xsl:template> 

<xsl:template name="MasterNested"> 

    <xsl:param name="current_node" select="bus1:BusinessInteractionType"/> 

    <xsl:if test="$current_node"> 
     <cas:businessInteractionTypeHas> 
      <cas:businessInteractionType> 
       <bus3:TypeId> 
        <xsl:value-of select="$current_node//bus1:TypeId"/> 
       </bus3:TypeId> 
       <bus3:Name> 
        <xsl:value-of select="$current_node//bus1:Name"/> 
       </bus3:Name> 
       <bus3:Description> 
        <xsl:value-of select="$current_node//bus1:Description"/> 
       </bus3:Description> 
      </cas:businessInteractionType> 
      <xsl:call-template name="MasterNested"> 
       <xsl:with-param name="current_node" select="$current_node/following-sibling::node()"/> 
      </xsl:call-template> 
     </cas:businessInteractionTypeHas> 
    </xsl:if> 
</xsl:template>