How to select an attribute based on another attribute's value

后端 未结 2 1593
南旧
南旧 2021-01-14 08:24

I need to select the NativeDescription value when Credit_Term_Code=\"4\" by looping in XSLT:


  

        
相关标签:
2条回答
  • 2021-01-14 08:54

    To select the NativeDescription attribute of the Credit_Term_parent element with a Credit_Term_Code equal to 4, use one of the following XPaths:

    1. If the ancestral structure above Credit_Term_parent is fixed as shown:

      /Credit_code_parents/Credit_Term_parent[@Credit_Term_Code='4']/@NativeDescription
      
    2. If there's potentially variable ancestral structure above Credit_Term_parent (and assuming that the provided Credit_Term_Code is unique across the document):

      //Credit_Term_parent[@Credit_Term_Code='4']/@NativeDescription
      

    You ask for XSLT looping code:

    <xsl:for-each select="/Credit_code_parents/Credit_Term_parent">
       <xsl:if test="@Credit_Term_Code=4">
         <xsl:value-of select="@Credit_Term_parent"/>
       </xsl:if>
    </xsl:for-each>
    

    Or, without the loop:

     <xsl:value-of
              select="//Credit_Term_parent[@Credit_Term_Code='4']/@NativeDescription"/>
    

    ...or, alternatively, use the XPath from #1 above instead of the one from #2.

    0 讨论(0)
  • 2021-01-14 09:20

    try the following

    <xsl:for-each select="Credit_code_parents/Credit_Term_parent">
      <xsl:variable name="temp" select="@Credit_Term_Code"/>
      <xsl:if test="$temp='1'">
        <check>
          <xsl:value-of select="@NativeDescription"/>
        </check>
      </xsl:if>
    </xsl:for-each>
    

    Hope that helps.

    0 讨论(0)
提交回复
热议问题