私の間違い、私はそれを明確にします:
簡単な質問がありますが、XSLT は初めてです。
私は2つのxmlファイルを持っています:
usa1.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<country>
<state name="CA">
<city name="Sunnyvale" county="Sant Clara">
<street number="123">
El Comino Ave.
</street>
</city>
<city name="San Jose" county="Sant Clara">
<street number="345">
De Anza Ave.
</street>
</city>
<city name="palo Alto" county="Sant Clara">
<street number="789">
Shoreline Ave.
</street>
</city>
</state>
</country>
usa2.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<country>
<state name="CA">
<city name="Sunnyvale" county="Sant Clara">
<street number="999">
Homestead Ave.
</street>
</city>
<city name="San Jose" county="Sant Clara">
<street number="888">
Airport Ave.
</street>
</city>
</state>
</country>
XSLT を使用して、サニーベール市とサンノゼ市のすべての値と属性を のusa1.xml
データに置き換えたいと考えていますusa2.xml
。
usa4.xml としてのアイデア出力:
usa4.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<country>
<state name="CA">
<city name="Sunnyvale" county="Sant Clara">
<street number="999">
Homestead Ave.
</street>
</city>
<city name="San Jose" county="Sant Clara">
<street number="888">
Airport Ave.
</street>
</city>
<city name="palo Alto" county="Sant Clara">
<street number="789">
Shoreline Ave.
</street>
</city>
</state>
</country>
これどうやってするの?
次の XSLT を試しましたが、返された出力は期待したものではありません。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="usaxml" select="'usa1.xml'" />
<xsl:variable name="address" select="document($usaxml)//" />
<xsl:template match="/">
<xsl:attribute name="number">
<xsl:value-of select="$address/@street" />
</xsl:attribute>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>