我坚持与先前兄弟相关的逻辑,
试图保持XML简单.
<order>
<orderList>
<itemid><id>100</id></itemid>
<itemid><id>100</id></itemid>
<itemid><id>111</id></itemid>
<itemid><id>111</id></itemid>
<itemid><id>123</id></itemid>
<itemid><id>324</id></itemid>
<itemid><id>244</id></itemid>
<itemid><id>244</id></itemid>
</orderList>
</order>
Run Code Online (Sandbox Code Playgroud)
我试图使用下面的xsl找到每个节点的前一个兄弟.我需要使用每个循环来适应这个逻辑在更大的xsl ...
<html>
<body>
<table border="1">
<xsl:for-each select="order/orderList/itemid">
<tr>
<td>itemid</td>
<td><xsl:value-of select="id" /> </td>
<td> <xsl:value-of select="preceding-sibling::node()"/> </td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
I get these Results
itemid 100
itemid 100 100
itemid 111 100
itemid 111 100 - expecting 111
itemid 123 100 - expecting 111 etc
itemid 324 100
itemid 244 100
itemid 244 100
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
我有这样的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>
Run Code Online (Sandbox Code Playgroud)
我正在使用此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>
Run Code Online (Sandbox Code Playgroud)
我尝试过祖先和前兄弟,对我不起作用..我期待以下结果
B.Id PartNo PreviousValue …Run Code Online (Sandbox Code Playgroud)