XML : XSLT if matching all XML tag contents

Problem : Given an xml file, get the value of content/id tag with value 'sam' using xslt

Issue: All the values matching the same path getting selected. Both brian and sam.

(I wondered the select should select the first match and shouldn't loop like for-each utility provided in xslt)

xml:

  <?xml version="1.0" encoding="UTF-8"?>  <Primary>    <PID>Tech1</PID>    <Version>1234</Version>    <AData>        <Id>widnows</Id>   </AData>   <BData>     <Content>        <Id>brian</Id>     </Content>     <Content>        <Id>sam</Id>     </Content>   </BData>  </Primary>`    

xslt

  <?xml version="1.0" encoding="utf-8" ?>  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">     <xsl:template match="/Primary">      <xsl:variable name="var" select="'sam'" />       <xsl:apply-templates select="BData/Content">           <xsl:if test="Id='sam'">           <xsl:value-of select="Id"/>           </xsl:if>      </xsl:apply-templates>    </xsl:template>  </xsl:stylesheet>    

No comments:

Post a Comment