2017-09-26 5 views
0

2つのノードがある場合は、内側のテキストを引き算してください。生成されたXSLTで2つのノードの内部テキストを引く方法

私のXMLは次のとおりです。

<?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> 
. 
. 
. 
. 
. 

私は差分を取得することはできませんよ(オリジナルのXMLがOriIndexまでです)。たとえば、<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

まあ、<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>が必要です。

+0

Martin Honnenに多くの感謝をします。それは正常に動作しています。私は実際には論理を欠いている。これをコード化する方法についてアドバイスをお願いしますか?私は、現在のOriIndex内部テキストと以前のOriIndex内部テキスト(これ以前のもの)の違いを知りたいと思います。私は:を入れましたが、コンパイルエラーです。助けてください。乾杯:) – newbuntu

関連する問題