XML : How to get first element value depending on attribute condition value when they are multiple elements in document xslt 2.0

I have a documents looks like below

  <list>      <document>          <content type="text" name="title" action="cluster" weight="3" output-action="bold" vse-streams="2" u="113">  Sample action steps/best practices</content>          <content type="html" name="title" output-action="bold" weight="3" vse-streams="2" u="146">  Survey Dimension: Excellence in All We Do</content>  <content name="fileextension" action="none" weight="1" type="text" output-action="bold" vse-streams="2" u="43">  pdf</content>  <content name="filetypelabel" action="none" weight="1" type="text" output-action="" vse-streams="2" u="45">  word</content>      </document>      <document>          <content type="text" name="title" action="cluster" weight="3" output-action="bold" vse-streams="2" u="113">  Sample steps/best practices</content>          <content type="html" name="title" output-action="bold" weight="3" vse-streams="2" u="146">  Survey : Excellence in All We Do</content>  <content name="fileextension" action="none" weight="1" type="text" output-action="bold" vse-streams="2" u="43">  excel</content>  <content name="filetypelabel" action="none" weight="1" type="text" output-action="" vse-streams="2" u="45">  ppt</content>      </document>  </list>    

when I transform it using xslt 2.0

      <?xml version="1.0" encoding="UTF-8"?>  <xsl:stylesheet version="2.0"      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"      xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"      xmlns:xdt="http://www.w3.org/2005/xpath-datatypes">      <xsl:template match="list/document">          <xsl:for-each select ="content">              <xsl:variable name="title" select="." />              <xsl:value-of select="$title" />          </xsl:for-each >      </xsl:template>  </xsl:stylesheet>    

I get the out as below

  <?xml version="1.0" encoding="utf-8"?>    Sample action steps/best practices  Survey Dimension: Excellence in All We Do  pdf  word    Sample steps/best practices  Survey : Excellence in All We Do  excel  ppt    

But my requirement is to consider the first element value when @name='title' in both documents.

So expected result should look like below

  <?xml version="1.0" encoding="utf-8"?>    Sample action steps/best practices    Sample steps/best practices    

No comments:

Post a Comment