xslt:使用属性值来检索另一个“相同父元素”元素的属性

时间:2017-05-01 17:42:50

标签: xml xslt attributes xslt-1.0 xslt-2.0

我有以下xml,其中可以有多个Person和Location元素:

<ProtectionOrderResponse>
  <Person id="PRTPER1">
    <!--child elements-->
  </Person>
  <Location id="PRTADR1"> 
    <!--child elements-->
  </Location>
  <PersonLocationAssociation>
        <PersonReference ref="PRTPER1"/>
        <LocationReference ref="PRTADR1"/>
  </PersonLocationAssociation>
</ProtectionOrderResponse>

我需要一个xslt,遍历每个Person元素以检索其id属性,并将其与PersonLocationAssociation / PersonReference的ref属性相匹配。从那里,我想获得属性值“PRTADR1”,并在给定Person属性值“PRTPER1”的情况下使用xslt将其放入变量中。 以下是我正在研究的xslt的简化版本:

<xsl:template match="//ProtectionOrderResponse">
  <!--Although I'm iterating through all the Person elements, I only want to select particular Person elements that match a specific criteria, not sure how to do this yet so I will put the logic in the template section-->
  <xsl:for-each select="//Person">
     <xsl:apply-templates select="."/>
  </xsl:for-each>
</xsl:template>

<xsl:template match="Person">
<!--Logic to only process the Person element that matches a particular criteria and get the LocationReference for that Person-->
<xsl:variable name="PerID" select="Person/@id"/>
  <!-- need to obtain the ref attribute value of PersonLocationAssociation/LocationReference for the PersonLocationAssociation/PersonReference[@ref=$PerID]-->
</xsl:template>

我需要的是获取PersonLocationAssociation / PersonReference [@ ref = $ PerID]的PersonLocationAssociation / LocationReference的ref属性值。我该怎么做?谢谢!

1 个答案:

答案 0 :(得分:1)

使用键:

<div class="dropdown" ng-mouseover="test()" ng-mouseleave="test2()" ng-click="test3()">
       <span>{{dropDownTimeEst}}</span>
       <i class="fa fa-caret-down bron-caret" aria-hidden="true"></i>
       <div class="dropdown-content" ng-show="showDropwDownTime">
           <a ng-repeat="item in times" ng-click="changeTimeEst(item); $event.stopPropagation();">{{item}}</a>
       </div>
</div>