xml - How to avoid duplicates generated from XSLT -


i have each loop on xslt file, go , process multiple conditions, if of conditions have matching scenario want exit out of loop , give first value(which has satisfied condition) output.

here xml file

     <product>      <contactdetails>      <addressdetail>      <street>stack</street>      <housenumber>123</housenumber>      </addressdetail>      <addressdetail>      <street>stack</street>      <housenumber>123456</housenumber>      </addressdetail>      <addressdetail>      <street>stack</street>      <housenumber>456</housenumber>      </addressdetail>      </contactdetails>      </product>  

and in xsl file have kinding this

    <?xml version="1.0" encoding="utf-8"?>     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform"                 version="2.0" xmlns:fo="http://www.w3.org/1999/xsl/format"                 xmlns:saxon="http://saxon.sf.net/" extension-element-prefixes="saxon"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>  <xsl:template match="/">              <p1:product_req>          <p2:contactdetails_req>         <xsl:for-each select ="product[contactdetails= 'addressdetails']  ">             <xsl:if test="street='stack'" >             <p3:sc>abc</p3:sc>             </xsl:if>          </xsl:for-each>          </p2:contactdetails_req>       </p1:product_req>   </xsl:template> </xsl:stylesheet>      

after transformation, having 3 values on output xml

          <p1:product_req>             <p2:contactdetails_req>                <p3:ac>abc</p3:ac>             <p3:ac>abc</p3:ac>             <p3:ac>abc</p3:ac>             </p1:product_req>             </p2:contactdetails_req>   

but dont need repeting values on output xml, need 1 value on xml node ac. have tried using identity transform nothing seems working, highly appreciated

<p1:product_req> <p2:contactdetails_req>     <p3:ac>abc</p3:ac> </p1:product_req> </p2:contactdetails_req>   

i need transformed output without duplicates.

your question not clear. if - seems - want test if @ least 1 address (in entire xml) has given street, simply:

<xsl:template match="/">     <xsl:if test="product/contactdetails/addressdetail/street='stack'" >             <!-- whatever want output goes here -->     </xsl:if> </xsl:template> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -