将部分父节点复制到子节点 XSLT



我想将节点从父节点复制到子节点。我不太确定如何实现这一目标。

我的源 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>

谢谢。

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
  <xsl:template match="/OrderItem/ProductionInformation/GSItem">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      <xsl:for-each select="/OrderItem">
        <xsl:apply-templates select="@*|node()[name()!='ProductionInformation']"/>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

相关内容

  • 没有找到相关文章

最新更新