我試圖打印基於最後一個節點的條件行。 這是一個XML示例:XSL:從前一個節點訪問數據
<point3d name="pts_p" index="0" x="-119.880476" y="2.012081" z="186.208920"/>
<double name="pts_tool" index="0">100.000000</double>
<point3d name="pts_p" index="1" x="-119.359576" y="-4.849939" z="186.220865"/>
<double name="pts_tool" index="1">100.000000</double>
<point3d name="pts_p" index="2" x="-117.434589" y="-11.072205" z="186.219202"/>
<double name="pts_tool" index="2">0.000000</double>
<point3d name="pts_p" index="3" x="-113.846437" y="-17.133645" z="185.787516"/>
<double name="pts_tool" index="3">100.000000</double>
<point3d name="pts_p" index="4" x="-107.697823" y="-22.645023" z="185.765083"/>
<double name="pts_tool" index="4">100.000000</double>
,並使用該XSL(樣品):
<xsl:if test="$toolpoint[@index = $i] = 0">
<xsl:text> SetDo RoughMotorOn, 0;
</xsl:text>
</xsl:if>
<xsl:if test="$toolpoint[@index = $i] = 100">
<xsl:text> SetDo RoughMotorOn, 1;
</xsl:text>
</xsl:if>
給我的輸出:
SetDo RoughMotorOn, 1;
MoveL [[-119.880476,....
SetDo RoughMotorOn, 1;
MoveL [[-119.359576,....
SetDo RoughMotorOn, 0;
MoveL [[-117.434589,....
SetDo RoughMotorOn, 1;
MoveL [[-113.846437,....
SetDo RoughMotorOn, 1;
MoveL [[-107.697823, ....
至極是正確的,但I'de喜歡刪除「冗餘」線,看起來像這樣
SetDo RoughMotorOn, 1;
MoveL [[-119.880476,....
MoveL [[-119.359576,....
SetDo RoughMotorOn, 0;
MoveL [[-117.434589,....
SetDo RoughMotorOn, 1;
MoveL [[-113.846437,....
MoveL [[-107.697823,....
有什麼辦法可以做到這一點?
在我最後一次嘗試我用這個XSL代碼:
<xsl:choose>
<xsl:when test="position()=1">
<xsl:if test="$toolpoint[@index = $i] = 0">
<xsl:text> SetDo RoughMotorOn, 0;
</xsl:text>
</xsl:if>
<xsl:if test="$toolpoint[@index = $i] = 100">
<xsl:text> SetDo RoughMotorOn, 1;
</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$toolpoint[@index = $i] = $toolpoint[@index != $i-1]">
<xsl:if test="$toolpoint[@index = $i] = 0">
<xsl:text> SetDo RoughMotorOn, 0;
</xsl:text>
</xsl:if>
<xsl:if test="$toolpoint[@index = $i] = 100">
<xsl:text> SetDo RoughMotorOn, 1;
</xsl:text>
</xsl:if>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
我真的很難理解你的問題。謹慎地闡述並提供**最小有效** .xml/.xsl而不是件? – FailedDev
你是對的,試圖清理代碼並結束清理太多 – vitohxc