Xml XSLT复制子模板中的父元素树
例如,我有一个XML:Xml XSLT复制子模板中的父元素树,xml,xslt,xslt-2.0,Xml,Xslt,Xslt 2.0,例如,我有一个XML: <ProcessPurchaseOrder > <PurchaseOrderLine> <DocumentReference type="sendersReference2"> <DocumentID> <ID>100</ID> </DocumentID> </Do
<ProcessPurchaseOrder >
<PurchaseOrderLine>
<DocumentReference type="sendersReference2">
<DocumentID>
<ID>100</ID>
</DocumentID>
</DocumentReference>
<DocumentReference type="sendersReference3">
<DocumentID>
<ID>ru</ID>
</DocumentID>
</DocumentReference>
<Item>
<CustomerItemID>
<ID>00126</ID>
</CustomerItemID>
</Item>
</PurchaseOrderLine>
<PurchaseOrderLine>
<DocumentReference type="sendersReference2">
<DocumentID>
<ID>200</ID>
</DocumentID>
</DocumentReference>
<DocumentReference type="sendersReference3">
<DocumentID>
<ID>ru</ID>
</DocumentID>
</DocumentReference>
<Item>
<CustomerItemID>
<ID>123122</ID>
</CustomerItemID>
</Item>
</PurchaseOrderLine>
</ProcessPurchaseOrder>
可能吗
UPD:
数据库响应XML部分
<DbResponse>
<ResultSet>
<Row>
<Cell name="WEANR" type="VARCHAR2">1909123</Cell>
<Cell name="ARTNR" type="VARCHAR2">00126</Cell>
<Cell name="WEPNR" type="VARCHAR2">1</Cell>
</Row>
<Row>
<Cell name="WEANR" type="VARCHAR2">1909123</Cell>
<Cell name="ARTNR" type="VARCHAR2">00126</Cell>
<Cell name="WEPNR" type="VARCHAR2">16</Cell>
</Row>
</ResultSet>
</DbResponse>
1909123
00126
1.
1909123
00126
16
它只是意味着WepNr
可以返回多个值:比如“116
”,在这种情况下,我想不是
<xsl:for-each select="*:PurchaseOrderLine">
<xsl:variable name="ArtNr" select="*:Item/*:CustomerItemID/*:ID"/>
<xsl:variable name="WepNr" select="/*/DbResponse/ResultSet/Row[Cell[@name='ARTNR']=$ArtNr][Cell[@name='WEANR']=$WeaNr]/Cell[@name='WEPNR']"/>
<xsl:copy>
<xsl:if test="$WepNr!=''">
<xsl:for-each select="$WepNr">
<LineNumber><xsl:value-of select="$WepNr/current()"/></LineNumber>
</xsl:for-each>
</xsl:if>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
及
当然,所有未经测试的代码,您最好提供最小但完整的代码样本,以便我们编写可测试的代码。请向我们展示您在
/*/DbResponse/ResultSet/Row[Cell[@name='ARTNR']=$ARTNR][Cell[@name='weaner']=$WEANR]/Cell[@name='WEPNR']]中尝试选择的元素的输入样本。
@MartinHonnen问题已更新
<DbResponse>
<ResultSet>
<Row>
<Cell name="WEANR" type="VARCHAR2">1909123</Cell>
<Cell name="ARTNR" type="VARCHAR2">00126</Cell>
<Cell name="WEPNR" type="VARCHAR2">1</Cell>
</Row>
<Row>
<Cell name="WEANR" type="VARCHAR2">1909123</Cell>
<Cell name="ARTNR" type="VARCHAR2">00126</Cell>
<Cell name="WEPNR" type="VARCHAR2">16</Cell>
</Row>
</ResultSet>
</DbResponse>
<xsl:for-each select="*:PurchaseOrderLine">
<xsl:variable name="ArtNr" select="*:Item/*:CustomerItemID/*:ID"/>
<xsl:variable name="WepNr" select="/*/DbResponse/ResultSet/Row[Cell[@name='ARTNR']=$ArtNr][Cell[@name='WEANR']=$WeaNr]/Cell[@name='WEPNR']"/>
<xsl:copy>
<xsl:if test="$WepNr!=''">
<xsl:for-each select="$WepNr">
<LineNumber><xsl:value-of select="$WepNr/current()"/></LineNumber>
</xsl:for-each>
</xsl:if>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:for-each>
<xsl:apply-templates select="*:PurchaseOrderLine"/>
<xsl:key name="row-by-wepnr"
match="DbResponse/ResultSet/Row"
use="Cell[@name='ARTNR']"/>
<xsl:template match="*:PurchaseOrderLine">
<xsl:variable name="this" select="."/>
<xsl:variable name="wepNrs" select="key('row-by-wepnr', *:Item/*:CustomerItemID/*:ID)[Cell[@name='WEANR']=$WeaNr]/Cell[@name='WEPNR']"/>
<xsl:for-each select="$wepNrs">
<xsl:apply-templates select="$this" mode="add-wep">
<xsl:with-param name="wep" select="current()"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="*:PurchaseOrderLine" mode="add-wep">
<xsl:param name="wep"/>
<xsl:copy>
<LineNumber><xsl:value-of select="$wep"/></LineNumber>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:apply-templates select="*:PurchaseOrderLine">
<xsl:with-param name"WearNr" select="$WearNr"/>
</xsl:apply-templates>
<xsl:template match="*:PurchaseOrderLine">
<xsl:param name="$WearNr"/>
<xsl:variable name="this" select="."/>
<xsl:variable name="wepNrs" select="key('row-by-wepnr', *:Item/*:CustomerItemID/*:ID)[Cell[@name='WEANR']=$WeaNr]/Cell[@name='WEPNR']"/>
<xsl:for-each select="$wepNrs">
<xsl:apply-templates select="$this" mode="add-wep">
<xsl:with-param name="wep" select="current()"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="*:PurchaseOrderLine" mode="add-wep">
<xsl:param name="wep"/>
<xsl:copy>
<LineNumber><xsl:value-of select="$wep"/></LineNumber>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>