ソースxmlからの特定の一致がターゲットxmlの異なるコンテキストに含まれるターゲットxmlにソースxmlを変換したいとします。異なるコンテキストで同じマッチストリングを持つテンプレートを呼び出す
:私のようなテンプレートを適用したい名前カスタマーのテンプレートでは<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:call-template name="root" />
</xsl:template>
<xsl:template name="root">
<root>
<xsl:apply-templates select="/shiporder"/>
<xsl:call-template name="Customer"/>
</root>
</xsl:template>
<xsl:template name="Customer">
<Customer>
<!--<xsl:apply-templates select="/shiporder"/>-->
</Customer>
</xsl:template>
<xsl:template match="/shiporder">
<xsl:apply-templates select="shipto"/>
</xsl:template>
<xsl:template match="/shiporder/shipto">
<Address>
<xsl:apply-templates select="text()"/>
</Address>
</xsl:template>
</xsl:stylesheet>
:私は、次のスタイルシートを適用し、このソースXMLに
<shiporder>
<shipto>orderperson1</shipto>
<shipto>orderperson1</shipto>
<city>London</city>
</shiporder>
:たとえば、私は、ソースXML等を有していて
<xsl:template match="/shiporder">
<xsl:apply-templates select="city"/>
</xsl:template>
<xsl:template match="/shiporder/city">
<City>
<xsl:apply-templates select="text()"/>
</City>
</xsl:template>
しかし、既に/shiporder
と一致するテンプレートを定義しました。だから私は同じマッチの両方のテンプレートがそれぞれのコンテキストで存在するスタイルシートをどのように設計するのか分かりません。
'mode'を使用してください - https://www.w3.org/TR/xslt/#modes –
あなたの質問はあいまいです。 1) '/ shiporder'は本当に何にもマッチできません。なぜならあなたの文書は'/root'で始まるからです。例として作業コードを使用してください。たとえそれが正しい結果をもたらさないとしても、それはそのような間違いを含むべきではありません。 2)あなたはどんな出力を期待しているかは言わなかった。入力サンプルと一致する出力を含めてください。 – Tomalak
@Tomalak私はあなたの文句を理解していません1)作業例[here](http://xsltransform.net/3NSSEuL/3)を参照してください – StellaMaris