2016-08-09 7 views
0

を使用して条件に従ってXMLの値を変更する方法XMLのように:私が持っているXSLT

予想される出力: 場合<present>true</present>

私はXSLを使ってXML変換を実行する

<all> 
    <one>Something 1</one> 
    <two>something 2</two> 
    <check> 
     <present>true</present> 
    </check> 
    <action> 
     <perform></perform> 
    </action> 
</all> 

all> 
    <one>Something 1</one> 
    <two>something 2</two> 
    <check> 
     <present>YES</present> 
    </check> 
    <action> 
     <perform>READ</perform> 
    </action> 
</all> 

else if:<present>false</present>

<all> 
    <one>Something 1</one> 
    <two>something 2</two> 
    <check> 
     <present>NO</present> 
    </check> 
    <action> 
     <perform>INSERT</perform> 
    </action> 
</all> 

できますか? 私は要素を移動しようとしたが働いていなかった条件は、XSL にチェックについて認識していない午前:

<xsl:template match="perform"> 
    <xsl:copy> 
    <xsl:choose> 
     <xsl:when test="../check/present = 'true'"> 
     <xsl:text>READ</xsl:text> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:apply-templates/> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:copy> 
</xsl:template> 

答えて

1

あなたはニーズが行われると言う正確に何をしていない理由:

<xsl:template match="perform"> 
    <xsl:copy> 
     <xsl:choose> 
      <xsl:when test="../../check/present='true'">READ</xsl:when> 
      <xsl:when test="../../check/present='false'">INSERT</xsl:when> 
     </xsl:choose> 
    </xsl:copy> 
</xsl:template> 
+1

ありがとうございます。それは働いた –

0

試用版:

<xsl:stylesheet version= "1.0" 
xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" > 
<xsl:output method= "xml" version= "1.0" encoding= "UTF-8" indent= "yes" /> 
<xsl:strip-space elements= "*" /> 

<!-- identity transform --> 
<xsl:template match= "@*|node()" > 
    <xsl:copy><xsl:apply-templates select= "@*|node()" /></xsl:copy> 
</xsl:template > 

<xsl:template match="action"/> 

<xsl:template match="check/present"> 
    <xsl:choose> 
      <xsl:when test=".='true'"> 
       <xsl:copy><xsl:text>YES</xsl:text></xsl:copy> 
       <action> 
        <perform><xsl:text>READ</xsl:text></perform> 
       </action> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:copy><xsl:text>NO</xsl:text></xsl:copy> 
       <action> 
        <perform><xsl:text>INSERT</xsl:text></perform> 
       </action> 
      </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
</xsl:stylesheet> 
+1

返信ありがとう.. –

+1

私はもう一つの懸念があります。ちょうど知りたがっているのは、xslファイルをgit repoに置いてローカルでの競合を読み込み、変換を行うことが可能かどうかです。 –

関連する問題