XSLT key element: "use" parent node in "match"

I seem to be unable to understand this thing. Is it possible to have the following key?

<xsl:key name="kMatchSentenceID_withTokId" match="sentences/sentence/@ID"
         use="--and here return the 'sentences' node--"/>

I don’t understand how “use” works, shouldn't that be the value you return when the match matches?

I see that it use="."returns the attribute value in my case. (Why? Is this a coincidence? .Means node()?, Not node()/@)

But most importantly, why I can not do something like this: use="parent::sentence[@ID=name()]"

How would I do that? I need a match on @ID, but return its parent (more specifically, the parent id).

Thank.

+3
source share
3 answers

, "", ? , ?

, use , "". :

use , ; node, .

use - , - match , . , match , use , .

, sentence @ID sentence. :

<xsl:key name="kMatchSentenceID_withTokId" match="sentences/sentence" 
         use="parent::*/@ID"/>

:

<xsl:key name="kMatchSentenceID_withTokId" match="sentences/sentence/@ID"
         use="parent::sentence[@ID=name()]"/>

... ID sentence, , .

+3

-

<sentences id="parent">
  <sentence id="childa"/>
  <sentence id="childb"/>
</sentences>

:

<xsl:key name="sentence" match="sentences" use="sentence/@id"/>

, , XPath key('sentence','childa')/@id 'parent'.

+1

, , . , , . : E, V P, <xsl:key name="N" match="E" use="P"/>, P - XPath, , E , ; key('N', V). XPath, , E .

, ; , .

+1

All Articles