このトピックのビルド: How do I select an XML node with the longest child #text node value with XPath? テーブルの列1で最も長いセルを見つけようとしています。残念ながら、私はテーブルが持っている祖先がいくつあるのか分からず、時々あるテキスト要素内にいくつかの異なる扱いが必要です。XSLT 2.0を使用してテーブル内で最も長いセルを見つける
XML
<text><table cols="3" rows="2">
<row >
<cell >first cell first row</cell>
<cell >second cell first row
</cell>
<cell >third cell first row
</cell>
</row>
<row >
<cell >first cell second row</cell>
<cell >this is an incredible long text</cell>
<cell />
</row>
</table>
</text>
XSLT:第二のカラムがないよう
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="table">
<xsl:variable name="longest1">
<xsl:sequence select=
"/*/table/row/cell[1][not(string-length(.) < /*/table/row/cell[1]/string-length(.))]"/>
</xsl:variable>
<xsl:value-of select="longest1">
</xsl:template>
</xsl:stylesheet>
コースの出力は、 "最初のセル第二行" でなければなりません処理される。 私は私がしなければならないすべては/ *この行の修正するためにはかなり確信している:
<xsl:sequence select=
"/*/table/row/cell[1][not(string-length(.) < /*/table/row/cell[1]/string-length(.))]"/>
をしかし、私は解決策を確認するために管理することはできません。
は、私は他の1が同じ長さの複数のセルがある場合に動作しませんでしたので、並べ替えを使用してソリューションに頼らなければならなかった: | | | | はAAAとしてコンパイルします。私はそれが「より低い」と関係があると思っていて、「より低いか等しい」でなければならないと思っていますが、それはそのトリックをしませんでした。もう一方のソートはすぐに処理されました! –
martinanton
'
ああ、実際の生活の中でそれを実装するときに私はそれを混乱させていたに違いない。 – martinanton