2016-04-09 11 views
0

XPathのselect式の2つの属性値を比較したいと思います...具体的には、typeのtid属性とpersonのcategory属性を比較したいと思います。それを動作させることは可能ですか? :)XSLTで選択したXPath内で親要素の属性を子の属性と比較することはできますか?

<xsl:template match="/people/type"> 
    <div class="type"> 
     <h3> 
      <a name="./{@tid}"><xsl:value-of select="./title"/></a> 
     </h3> 
     <ul> 
      <lh>Persons with this type:</lh> 
       <xsl:apply-templates select="../employees/person[@[email protected]]"/> <!-- here I would like to pass attribute tid of an type element --> 
     </ul> 
    </div> 
</xsl:template> 

答えて

1

はい、これは、表現のコンテキストを考慮すると簡単に可能です。

/people/type<xsl:template match="/people/type">によって作成された式のコンテキストです。

/employees/person[@category...]<xsl:apply-templates select="../employees/person[@[email protected]]"/>によって作成された別のコンテキストを適用しようとすると、2つのコンテキストがあります。 @category@tidのコンテキストは異なります。

解決策は簡単です。 1つのコンテキストを修正するだけでxsl:variable

<xsl:template match="/people/type"> 
    <xsl:variable name="typeID" select="@tid" /> <!-- fixing @tid of '/people/type' to $typeID --> 
    ... 
    <xsl:apply-templates select="/employees/person[@category=$typeID]"/> <!-- using $typeID --> 
    ... 
</xsl:template> 
+0

ありがとうございます!あなたは私の日を救った:) – user3216673

関連する問題