次のxmlファイルがあります。
<root_tag>
<tag1>
<tag1_1>A</tag1_1>
<tag1_2>B</tag1_2>
<tag1_3>C</tag1_3>
</tag1>
<tag2>
<tag2_1>D</tag2_1>
<tag2_2>
<elem xmlns="http://a.b.com/sample">
<elem_1>E</elem_1>
<elem_2>F</elem_2>
</elem>
</tag2_2>
</tag2></root_tag>
および xslt テンプレート:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<NODE>
<node1>
<xsl:value-of select="/root_tag/tag1/tag1_2"/>
</node1>
<node2>
<xsl:value-of select="/root_tag/tag2/tag2_1"/>
</node2>
<node3>
<xsl:value-of select="/root_tag/tag2/tag2_2/child::*[local-name(.) = 'elem']/child::*[local-name(.) = 'elem_1']"/>
</node3>
<xsl:variable name="A" select="namespace-uri(/root_tag/tag2/tag2_2/child::*[local-name(.) = 'elem'])"/>
<node4>
<xsl:value-of select="$A"/>
</node4>
<node5>
<!-- some code here -->
</node5>
</NODE>
</xsl:template>
出力は次のとおりです。
<NODE>
<node1>B</node1>
<node2>D</node2>
<node3>E</node3>
<node4>http://a.b.com/sample</node4>
<node5></node5>
</NODE>
node3 のような xpath を使用せずに、 node5 で/root_tag/tag2/tag2_2/elem/elem_1の値を取得する方法はありますか? elem の名前空間を格納する変数 A を何らかの形で使用できますか?
また、 xsl:stylesheetタグにxmlns:a_1="http://abcom/sample"を追加し、xpath /root_tag/tag2/tag2_2/a_1:elem/a_1:elem_1を使用して情報を抽出することもできましたが、これだけです。名前空間が事前にわかっている場合をカバーします。