我想将节点从父节点复制到子节点。我不太确定如何实现这一目标。
我的源 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>
谢谢。
<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="*"/>
以获得更好的格式)。