
[英]Need to read the previous node's child values to format the current node's value using xsl?
[英]XSL - Previous node value in the loop
我有这样的XML - (简化)
<OrderBundle>
<BundleDetail>
<BundleId>12312</BundleId>
<BundleUnit>
<Idset>
<PartNo>807651</PartNo>
</Idset>
</BundleUnit>
</BundleDetail>
<BundleDetail>
<BundleId>12112</BundleId>
<BundleUnit>
<Idset>
<PartNo>807650</PartNo>
</Idset>
</BundleUnit>
</BundleDetail>
<BundleDetail>
<BundleId>12412</BundleId>
<BundleUnit>
<Idset>
<PartNo>807651</PartNo>
</Idset>
</BundleUnit>
</BundleDetail>
<BundleDetail>
<BundleId>12612</BundleId>
<BundleUnit>
<Idset>
<PartNo>807651</PartNo>
</Idset>
</BundleUnit>
</BundleDetail>
</OrderBundle>
我正在使用此XSL来查找循环中类似节点的先前值。 我在这里简化了xsl,我需要在更大的集合中使用这个逻辑。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<th>Bundle Id</th>
<th>PartNo</th>
<th>PreviousValue</th>
</tr>
<xsl:for-each select="/OrderBundle/BundleDetail">
<tr>
<td> <xsl:value-of select="BundleId"/></td>
<td><xsl:value-of select=" BundleUnit/Idset/PartNo" /> </td>
<td> ?? <xsl:value-of select="ancestor::BundleUnit/Idset/PartNo"/> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
我尝试过祖先和前兄弟,对我不起作用..我期待以下结果
B.Id PartNo PreviousValue
12312 807651 ?? --
12112 807650 ?? -- 807651
12412 807651 ?? -- 807650 etc
12612 807651 ??
有什么想法吗?
用途 :
preceding-sibling::BundleDetail[1]/BundleUnit/Idset/PartNo
完整的转变成为 :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<th>Bundle Id</th>
<th>PartNo</th>
<th>PreviousValue</th>
</tr>
<xsl:for-each select="/OrderBundle/BundleDetail">
<tr>
<td> <xsl:value-of select="BundleId"/></td>
<td><xsl:value-of select=" BundleUnit/Idset/PartNo" /> </td>
<td><xsl:value-of
select="preceding-sibling::BundleDetail[1]/BundleUnit/Idset/PartNo"/> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
产生了想要的正确结果 :
<html xmlns:fo="http://www.w3.org/1999/XSL/Format">
<body>
<table border="1">
<tr>
<th>Bundle Id</th>
<th>PartNo</th>
<th>PreviousValue</th>
</tr>
<tr>
<td>12312</td>
<td>807651</td>
<td></td>
</tr>
<tr>
<td>12112</td>
<td>807650</td>
<td>807651</td>
</tr>
<tr>
<td>12412</td>
<td>807651</td>
<td>807650</td>
</tr>
<tr>
<td>12612</td>
<td>807651</td>
<td>807651</td>
</tr>
</table>
</body>
</html>
我认为<xsl:value-of select="preceding-sibling::BundleDetail[1]/BundleUnit/Idset/PartNo"/>
就是你要找的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.