0
<Request xmlns:ns0="http://Request">
  <Lines>
    <Line>
      <requestid>76</requestid>
      <Code>C001</Code>
    </Line>
    <Line>
      <requestid>77</requestid>
      <Code>C002</Code>
    </Line>
  </Lines>      
  <Conflict>
    <responseid>76</responseid>
    <responsecode>WB</responsecode>
    <cService>
      <responseid>73</responseid>
      <responsecode>HA</responsecode>
    </cService>
    <cService>
      <responseid>7600</responseid>
      <serviceCode>PP</serviceCode>
    </cService>
  </Conflict>      
  <Conflict>
    <responseid>77</responseid>
    <responsecode>WB7</responsecode>
    <cService>
      <responseid>745</responseid>
      <responsecode>HAQ</responsecode>
    </cService>
    <cService>
      <responseid>7234</responseid>
      <serviceCode>PP</serviceCode>
    </cService>
  </Conflict>      
  <Conflict>
    <responseid>77</responseid>
    <responsecode>WBC</responsecode>
    <cService>
      <responseid>72341</responseid>
      <responsecode>HAC</responsecode>
    </cService>
    <cService>
      <responseid>98</responseid>
      <responsecode>PPC</responsecode>
    </cService>
  </Conflict>
</Request>

必要な出力は次のようになります。

    <Output xmlns:ns0="http://Response">
      <Lines>
        <Line>
          <responseid>76</responseid>
          <code>WB</code>
          <Features>
            <ExistingFeature>
              <responseid>76</responseid>                           
              <CFeature>
                <responseid>76</responseid>                             
              </CFeature>
              <CFeature>
                <responseid>76</responseid>                                
              </CFeature>
            </ExistingFeature>
          </Features>
        </Line>
        <Line>
          <Num>77</Num>
          <Features>
            <ExistingFeature>
              <responseid>77</responseid>
              <code>WB7</code>
              <CFeature>
                <responseid>77</responseid>                
              </CFeature>
              <CFeature>
                <responseid>77</responseid>                
              </CFeature> 
              <CFeature>
                <responseid>77</responseid>                
              </CFeature> 
          <CFeature>
                <responseid>77</responseid>                
              </CFeature>             
            </ExistingFeature>
          </Features>
        </Line>        
      </Lines>
</Output>

XSLTでこれを達成するのを手伝ってください。私は複数の方法で試していますが、xsltが苦手なのでできません。

シナリオ。実際には、入力の各行に対して 1 つの行が作成され、requestID (つまり 76 または 77) に基づいて、入力の各行ごとに 1 つ以上の競合が存在する必要があります。したがって、これらの ID に基づいて、入力内の行が出現するたびに出力内の単一のノードに競合をグループ化し、入力内の対応するすべての一致する競合をグループ化する必要があります。

このシナリオの xslt を書くのを手伝ってくれませんか。

4

2 に答える 2

0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" />
  <xsl:key name="incomekey" match="/Request/Conflict" use="responseid" /> 
  <xsl:template match="/Lines" >
    <Lines>
      <xsl:apply-templates select="Line" />
    </Lines>
  </xsl:template>
  <xsl:template match="Line" >
    <Line>
      <xsl:variable name="tmp" select="requestid" />
      <xsl:for-each select="key('incomekey', $tmp)" >
        <xsl:variable name="strCount" select="position()" />
        <xsl:if test="position() &lt; 2">
          <responseid>
            <xsl:value-of select="requestid/text()" />
          </responseid>
          <code>
            <xsl:value-of select="Code/text()" />
          </code>
        </xsl:if>
        <Features>
          <ExistingFeature>
            <responseid>
              <xsl:value-of select="responseid" />
            </responseid>
            <code>
              <xsl:value-of select="responsecode" />
            </code>
            <xsl:for-each select="cService">
              <CFeature>
                <responseid>
                  <xsl:value-of select="responseid"/>
                </responseid>                              
              </CFeature>
            </xsl:for-each>
          </ExistingFeature>
        </Features>
      </xsl:for-each>
    </Line>
  </xsl:template>
</xsl:stylesheet>

上記のスクリプトを使用しています。ただし、以下に示すように、Second Line(77)の出力を生成します。

于 2012-11-24T20:46:50.520 に答える
0
<Line>
        <responseid>77</responseid>
        <code>WB</code>
        <Features>
          <ExistingFeature>
            <responseid>77</responseid>
            <code>WB7</code>
            <CFeature>
              <responseid>745</responseid>
            </CFeature>
            <CFeature>
              <responseid>7234</responseid>
            </CFeature>
          </ExistingFeature>
        </Features>
          <Features>
            <ExistingFeature>
              <responseid>77</responseid>
              <code>WBC</code>
              <CFeature>
                 <responseid>72341</responseid>
              </CFeature>
              <CFeature>
                <responseid>98</responseid>
              </CFeature>
             </ExistingFeature>
        </Features>
      </Line>

このノードを観察すると、77(RequestID)を使用したリクエストの競合ノードごとに2つの個別の機能ノードが作成されます。そのため、出力の2番目のLineノードに以下に示すようにデータを入力する必要があります。

<Features>
    <ExistingFeature>
      <responseid>77</responseid>
      <code>WB7</code>
      <CFeature>
        <responseid>745</responseid>
      </CFeature>
      <CFeature>
        <responseid>7234</responseid>
      </CFeature>
      <CFeature>
        <responseid>72341</responseid>
      </CFeature>
      <CFeature>
        <responseid>98</responseid>
      </CFeature>
    </ExistingFeature>
  </Features>
于 2012-11-24T20:56:11.017 に答える