xmlを新しい構造に変換してから、変換内で新しい構造を処理しようとしています。私の問題は、新しい構造をノードセットとして使用できるようにすることです。Webアプリケーションのライブラリでsaxon9heとともにTomcat6を使用しています。新しい構造の使いやすさをテストするために、次のxslを作成しました。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes" encoding="UTF-8"/>
<xsl:include href="nodeTest.xsl"/>
<xsl:variable name="theDoc">
<doc>
<source>from</source>
<source>here</source>
<target>to</target>
<target>there</target>
</doc>
</xsl:variable>
<xsl:template match="/">
<xsl:variable name="result1">
<xsl:call-template name="createLinks">
<xsl:with-param name="doc" select="$theDoc/doc/*"/>
</xsl:call-template>
</xsl:variable>
input:
<xsl:value-of select="$theDoc/doc/*"/>
output:
<xsl:value-of select="$result1"/>
</xsl:template>
</xsl:stylesheet>
変数theDocには有効なノードセットが含まれ、createLinksテンプレートはそれをノードセットとして処理することを期待しています。これがcreatlelInksテンプレートです。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="node()" mode="makeLink">
<xsl:param name="theSource" select="'source'"/>
<xsl:param name="theTarget" select="'target'"/>
<xsl:param name="theUsage" select="'usage'"/>
<xsl:element name="link" >
<xsl:element name="usage" ><xsl:value-of select="$theUsage"/></xsl:element>
<xsl:element name="source" ><xsl:value-of select="$theSource"/></xsl:element>
<xsl:element name="target" ><xsl:value-of select="$theTarget"/></xsl:element>
</xsl:element>
</xsl:template>
<xsl:template name="createLinks">
<xsl:param name="doc" select="*"/>
the input doc:
<xsl:value-of select="$doc"/>
<xsl:copy>
<xsl:element name="Links">
<xsl:apply-templates mode="makeLink" select=".">
<xsl:with-param name="theUsage" select="'link from source to target'"/>
<xsl:with-param name="theSource" select="$doc/source/*"/>
<xsl:with-param name="theTarget" select="$doc/target/*"/>
</xsl:apply-templates>
</xsl:element>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
実行すると、結果は次のようになります。
<?xml version="1.0" encoding="UTF-8"?>
input:
from here to there
output:
the input doc:
fromheretotherelink from source to target
theDocがノードセットではないことは明らかです。私の理解では、xslt 2.0標準では、結果ツリーフラグメントではなく、ノードセットとしてtheDocが使用されます。これらの単純なxslsを変更して、Docの内容をノードセットとして処理するにはどうすればよいですか?