:**どの要素として型指定されたXML変数にXPathクエリを適用する()* **XSLT関数の戻り値の型
私はXSLT 2.0の関数に渡された変数にXPathクエリを適用したいです。
サクソンこのエラーを返す:プログラムの
Type error at char 6 in xsl:value-of/@select on line 13 column 50 of stackoverflow_test.xslt:
XTTE0780: Required item type of result of call to f:test is element(); supplied value has item type text()
この骨格は、その開発の終わりまでに、複数のXSLT関数に要素ツリーを通過することを意味する、簡略化されるが。各関数は特定の統計を抽出し、ツリーからレポートを作成します。
XPathクエリを適用すると、変数に基本要素が含まれているとみなしたいと思っています。私が{count(doc( "My XSLT tree /要素変数 ")/ a [1])}となります。
サクソンHE 9.7.0.5の使用。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="f:f">
<xsl:template match="/root">
<xsl:variable name="first" as="element()*">
<xsl:copy-of select="(./a[1])" />
</xsl:variable>
<html>
<xsl:copy-of select="f:test($first)" />
</html>
</xsl:template>
<xsl:function name="f:test" as="element()*">
<xsl:param name="frstElem" as="element()*" />
<xsl:value-of select="count($frstElem/a)" />
<!-- or any XPath expression -->
</xsl:function>
</xsl:stylesheet>
いくつかの例データ
<root>
<a>
<b>
<c>hi</c>
</b>
</a>
<a>
<b>
<c>hi</c>
</b>
</a>
</root>
おそらく関連する質問:How to apply xpath in xsl:param on xml passed as input to xml
あなたはどのような結果を期待していますか? 'b'子を持つ' a'要素を渡すと、 'count($ frstElem/a)'の結果は0になります。 –
私はちょっと質問を編集しました。これは、私が正しい軌道に乗っているという確信を与えますが、コンパイラはそのことに気にしません。 –