简体   繁体   中英

How to do validate xslt i want to only validate three tag?

Hi i have XSLT file and i want to validate it .

i have more tag in xml file "sell", "rent", "Buy", "n/a", "NA", ""

But i want to show only if i have any three tag as like

"sell", "rent" and "buy" than show to this tag.

xml file

     <cd>
        <title>Rohit</title>
        <recomondation>buy</recomondation>
        <year>1985</year>
    </cd>
<cd>
        <title>Raj</title>
        <recomondation>n/a</recomondation>
        <year>2090</year>
    </cd>
<cd>
        <title>amit</title>
        <recomondation>rent</recomondation>
        <year>1990</year>
    </cd>
<cd>
        <title>kavi</title>
        <recomondation>sell</recomondation>
        <year>2012</year>
    </cd>
<cd>
        <title>jokesh</title>
        <recomondation>NA</recomondation>
        <year>1990</year>
    </cd>
<cd>
        <title>james</title>
        <recomondation>Rent</recomondation>
        <year>1890</year>
    </cd>

if recomondation tag "sell", "rent" and "buy" than recomondation data show otherwise not show.

i have found one link in stackoverflown but im not understand .

Please help me

You can try something like this

  <xsl:for-each select="cd[recomondation='sell' or recomondation='rent' or recomondation='buy']">
    <xsl:copy-of select="."/>
  </xsl:for-each>

This will cause an iteration on all cd nodes whose child recommendation node contain your mentioned data. With your sample data currently only three nodes will be filtered out. If you are looking only for the recommendation nodes then you can try this

  <xsl:for-each select="cd//recomondation[.='sell' or .='rent' or .='buy']">
    <xsl:value-of select="."/>
  </xsl:for-each>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM