我在尝试转换以下内容时遇到问题。输入具有父子关系,如下所示。Parent_Identifier
标签有助于将孩子与父母联系起来。XSLT 转换有什么问题?我使用了这篇文章中提到的转换:Xslt group parent/child,但我似乎无法让它工作。
输入文件
<DBAdapterOutputCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/DBAdapter">
<DBAdapterOutput>
<LEVEL>1</LEVEL>
<IDENTIFIER>9536162</IDENTIFIER>
<PARENT_IDENTIFIER xsi:nil="true"/>
<LINE_NUMBER>1.1.0</LINE_NUMBER>
</DBAdapterOutput>
<DBAdapterOutput>
<LEVEL>2</LEVEL>
<IDENTIFIER>9536165</IDENTIFIER>
<PARENT_IDENTIFIER>9536162</PARENT_IDENTIFIER>
<LINE_NUMBER>1.1.1</LINE_NUMBER>
<ORDER_NUMBER>1554828</ORDER_NUMBER>
</DBAdapterOutput>
<DBAdapterOutput>
<LEVEL>2</LEVEL>
<IDENTIFIER>9536173</IDENTIFIER>
<PARENT_IDENTIFIER>9536162</PARENT_IDENTIFIER>
<LINE_NUMBER>1.1.7</LINE_NUMBER>
<ORDER_NUMBER>1554828</ORDER_NUMBER>
</DBAdapterOutput>
<DBAdapterOutput>
<LEVEL>3</LEVEL>
<IDENTIFIER>1227973</IDENTIFIER>
<PARENT_IDENTIFIER>9536165</PARENT_IDENTIFIER>
<LINE_NUMBER>1.1.4</LINE_NUMBER>
<ORDER_NUMBER>1554828</ORDER_NUMBER>
</DBAdapterOutput>
<DBAdapterOutput>
<LEVEL>3</LEVEL>
<IDENTIFIER>1275015</IDENTIFIER>
<PARENT_IDENTIFIER>9536165</PARENT_IDENTIFIER>
<LINE_NUMBER>1.1.4</LINE_NUMBER>
<ORDER_NUMBER>1554828</ORDER_NUMBER>
</DBAdapterOutput>
</DBAdapterOutputCollection>
预期输出文件
<WMSAssetInterface_Input xmlns="http://siebel.com/CustomUI">
<ListOfAsset xmlns="http://www.siebel.com/xml/ThinComergentAsset">
<ListOfAssetHeader>
<AssetHeader>
<IntegrationId>9536162 1.1.0</IntegrationId>
<ProductName>1.1.0</ProductName>
<ListOfAssetItem>
<AssetItem>
<IntegrationId>9536162 1.1.0 Level=1</IntegrationId>
<ProductName>1.1.0</ProductName>
<ListOfAssetItem>
<AssetItem>
<IntegrationId>9536165 1.1.1 Level=2</IntegrationId>
<ProductName>1.1.1</ProductName>
<ListOfAssetItem>
<AssetItem>
<IntegrationId>1227973 1.1.4 Level=3</IntegrationId>
<ProductName>1.1.4</ProductName>
</AssetItem>
<AssetItem>
<IntegrationId>1275015 1.1.4 Level=3</IntegrationId>
<ProductName>1.1.4</ProductName>
</AssetItem>
</ListOfAssetItem>
</AssetItem>
<AssetItem>
<IntegrationId>9536173 1.1.7 Level=2</IntegrationId>
<ProductName>1.1.7</ProductName>
</AssetItem>
</ListOfAssetItem>
</AssetItem>
</ListOfAssetItem>
</AssetHeader>
<ListOfAssetHeader>
</ListOfAsset>
</WMSAssetInterface_Input>
这是我正在尝试使用的 XSLT;为什么这不起作用?
<xsl:stylesheet version="1.0" xmlns:ns0="http://xmlns.oracle.com/pcbpel/adapter/db/DBAdapter" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsdLocal1="http://www.siebel.com/xml/ThinComergentAsset" xmlns:tns="http://siebel.com/CustomUI" exclude-result-prefixes="tns" >
<xsl:template match="/ns0:DBAdapterOutputCollection">
<tns:WMSAssetInterface_Input>
<xsdLocal1:ListOfAsset>
<xsdLocal1:ListOfAssetHeader>
<xsdLocal1:AssetHeader>
<xsdLocal1:IntegrationId>
<xsl:value-of select='concat(ns0:DBAdapterOutput/ns0:IDENTIFIER," ",ns0:DBAdapterOutput/ns0:LINE_NUMBER," Level=",ns0:DBAdapterOutput/ns0:LEVEL)'/>
</xsdLocal1:IntegrationId>
<xsdLocal1:ProductName>
<xsl:value-of select="ns0:DBAdapterOutput/ns0:LINE_NUMBER"/>
</xsdLocal1:ProductName>
<xsl:apply-templates select="ns0:DBAdapterOutputCollection/ns0:DBAdapterOutput[string-length(ns0:PARENT_IDENTIFIER)=0]" />
</xsdLocal1:AssetHeader>
</xsdLocal1:ListOfAssetHeader>
</xsdLocal1:ListOfAsset>
</tns:WMSAssetInterface_Input>
</xsl:template>
<xsl:template match="ns0:DBAdapterOutput">
<xsdLocal1:ListOfAssetItem>
<xsdLocal1:AssetItem>
<xsdLocal1:IntegrationId>
<xsl:value-of select='concat(ns0:IDENTIFIER," ",ns0:LINE_NUMBER," Level=",ns0:LEVEL)'/>
</xsdLocal1:IntegrationId>
<xsdLocal1:PartName>
<xsl:value-of select="ns0:LINE_NUMBER"/>
</xsdLocal1:PartName>
<xsl:variable name="children" select="parent::*/ns0:DBAdapterOutput[ns0:PARENT_IDENTIFIER=current()/ns0:IDENTIFIER]" />
<xsl:if test="$children">
<xsdLocal1:ListOfAssetItem>
<xsdLocal1:AssetItem>
<xsl:apply-templates select="$children" />
</xsdLocal1:AssetItem>
</xsdLocal1:ListOfAssetItem>
</xsl:if>
</xsdLocal1:AssetItem>
</xsdLocal1:ListOfAssetItem>
</xsl:template>
</xsl:stylesheet>