1

「テスト」要素をツリーの最後の要素に追加しようとしていますが、要素ごとに繰り返されます。

<root>
   <Module>
      <Router>
         <Message>@OppositeMacAddress='0x00, 0x80, 0xC8, 0x3B, 0xC6, 0xA0'</Message>
         @OppositeMacAddress='0x00, 0x80, 0xC8, 0x3B, 0xC6, 0xA0'
      </Router>
      @OppositeMacAddress='0x00, 0x80, 0xC8, 0x3B, 0xC6, 0xA0'
   </Module> 
</root>

これは私の XML ソースです

   <fired-rule context="Message[@Name='SPY_IN']"/>
       <failed-assert
               test="@OppositeIpAddress='192,168,1,2'"
               location="/Module[1]/Router[1]/Message[1]">
       <text>!Error! Erwarteter Wert:"192,168,1,2"</text>
   </failed-assert>

次のようになります。

<root>
   <Module>
      <Router>
         <Message>@OppositeMacAddress='0x00, 0x80, 0xC8, 0x3B, 0xC6, 0xA0'</Message>
      </Router>
   </Module>
</root>

これが私の XSL 変換です

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="/">
    <root>
      <xsl:apply-templates select="//failed-assert/@location" />
    </root>
  </xsl:template>

  <xsl:template match="@location">
    <xsl:param name="path" select="." />

    <xsl:variable
        name="currentContext" 
        select="substring-before(substring-after($path,'/'), '[')"/>

    <xsl:variable name="subContext" select="substring-after($path, ']')"/>

    <xsl:element name="{$currentContext}">
      <xsl:apply-templates select="current()[string($subContext)]">
        <xsl:with-param name="path" select="$subContext"/>
      </xsl:apply-templates>
      <xsl:value-of select="../@test"/>
    </xsl:element>

  </xsl:template>

</xsl:stylesheet>

どうすればこの問題を解決できますか?

4

2 に答える 2