0

ノードを親から子にコピーしたい。これがどのように達成できるかはよくわかりません。

私のソースxml

<Root1>
    <Family1>
      <Childrens>
        <Child>
          <ChildFirstName>Robin1</ChildFirstName>
          <ChildLastName>Jackman1</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>

                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin2</ChildFirstName>
          <ChildLastName>Jackman2</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>

                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin3</ChildFirstName>
          <ChildLastName>Jackman3</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>

                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
      </Childrens>
    </Family1>
  </Root1>

出力を次のように取得したい

<Root1>
    <Family1>
      <Childrens>
        <Child>
          <ChildFirstName>Robin1</ChildFirstName>
          <ChildLastName>Jackman1</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>
                  <ChildFirstName>Robin1</ChildFirstName>
                  <ChildLastName>Jackman1</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>
                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin2</ChildFirstName>
          <ChildLastName>Jackman2</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>
                  <ChildFirstName>Robin2</ChildFirstName>
                  <ChildLastName>Jackman2</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>
                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
        <Child>
          <ChildFirstName>Robin3</ChildFirstName>
          <ChildLastName>Jackman3</ChildLastName>
          <Address>
            <Street1>Street1</Street1>
            <State>State</State>
            <Country>Country</Country>
          </Address>
          <Activities>
            <Sports>
              <Cricket>
                <ParticipentNames>
                  <ChildFirstName>Robin3</ChildFirstName>
                  <ChildLastName>Jackman3</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>
                </ParticipentNames>
              </Cricket>
            </Sports>
          </Activities>
        </Child>
      </Childrens>
    </Family1>
  </Root1>

XSLT 1.0 で解決したい。

これらのノードを子ノードにコピーしたい

                  <ChildFirstName>Robin3</ChildFirstName>
                  <ChildLastName>Jackman3</ChildLastName>
                  <Address>
                    <Street1>Street1</Street1>
                    <State>State</State>
                    <Country>Country</Country>
                  </Address>

ありがとう。

4

1 に答える 1

2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

<xsl:template match="ParticipentNames">
  <xsl:copy>
    <xsl:apply-templates select="ancestor::Child/ChildFirstName | ancestor::Child/ChildLastName | ancestor::Child/Address"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

十分なはずです(より良いフォーマットのために追加<xsl:output indent="yes"/>したいかもしれません)。<xsl:strip-space elements="*"/>

于 2012-05-08T11:39:11.573 に答える