次のいずれかのような XML があります。
// #1
<A>
<B>... stuff ...</B>
</A>
// #2
<B>... stuff ...</B>
これらを、両方のインスタンスで同じように見える応答ノードに変換する必要があります。このような並べ替え:
<fooMethodResponse>
... one thing from A if A was root ...
... stuff from B ...
</fooMethodResponse>
自分自身を繰り返さずにこれを最も簡単に行うにはどうすればよいですか? 私は今これをやった:
<xsl:template match="/A">
<fooMethodResponse>
<xsl:apply-templates select="B" mode="get-B" />
<xsl:element name="processId">
<xsl:value-of select="@id" />
</xsl:element>
</fooMethodResponse>
</xsl:template>
<xsl:template match="/B">
<fooMethodResponse>
<xsl:apply-templates select="." mode="get-B" />
</fooMethodResponse>
</xsl:template>
<xsl:template match="B" mode="get-B"></xsl:template>
ここでの問題は、応答ラッパーを繰り返していることです。それを 1 か所だけにしたいのです。私はこのようなことができると考えました:
<xsl:template match="/">
<fooMethodResponse>
<xsl:choose>
<xsl:when test="node name is A">
<xsl:when test="node name is B">
</xsl:choose>
</fooMethodResponse>
</xsl:template>
しかし、ルート要素のノード名を確認するテストの書き方がわかりません。ルート要素はどういうわけか異なる方法で処理されますか?
より正確な例を挙げたいと思いますが、そこにはかなりのビジネス関連のものがあるので、要約してみました :p