如果是2个节点,请你帮我减去内部文本。
我生成的xml是:(原始XML直到OriIndex)
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
<Test>
<TestPhase>1</TestPhase>
<TestFlow>1</TestFlow>
<TestParameter>1</TestParameter>
<OriIndex>0</OriIndex>
<SortedIndex>0</SortedIndex>
<Diff>NaN</Diff>
</Test>
.
.
.
.
.
我无法获得差异。例如,它应该是<SortedIndex>10</SortedIndex> - <OriIndex>5</OriIndex> Equals
5。
我的XSLT是:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding = "UTF-8" indent="yes" omit-xml-declaration="no" standalone="yes" />
<xsl:template match="Root">
<xsl:copy>
<xsl:apply-templates select="Test">
<xsl:sort select="TestPhase" data-type="number" order="ascending"/>
<xsl:sort select="TestFlow" data-type="number" order="ascending"/>
<xsl:sort select="TestParameter" data-type="number" order="ascending"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Test">
<xsl:copy>
<xsl:apply-templates select="@* | *"/>
<SortedIndex><xsl:value-of select="position() - 1"/></SortedIndex>
<Diff><xsl:value-of select="@SortedIndex - @OriIndex" /></Diff>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
请帮忙。非常感谢您的努力。
非常感谢。
干杯, newbuntu
答案 0 :(得分:0)
好吧,<Diff><xsl:value-of select="@SortedIndex - @OriIndex" /></Diff>
会计算该名称的属性之间的差异,你没有属性。如果您想计算子元素的差异,则需要<Diff><xsl:value-of select="SortedIndex - OriIndex" /></Diff>
。但是,部分您不清楚的说明听起来好像您在原始输入中没有SortedIndex
但只是使用XSLT为结果创建它,在这种情况下您需要<Diff><xsl:value-of select="position() - 1 - OriIndex" /></Diff>
。< / p>