xml - How to get the Count of the Child nodes based on node value? -


i have following xml.

<result>     <message>       <type>error</type>       <description>abc</description>     </message>     <message>       <type>warning</type>       <description>def</description>     </message>     <message>       <type>error</type>       <description>ghi</description>     </message>     <message>       <type>information</type>       <description>ijk</description>     </message> </result> 

i want result like

abc def ghi jkl  total error: 2 total warning: 1 total information:1 

i able total number of child records using count(//message/type), resulting 4.

i wants total number of errors, tried

count(//message/type &eq; "error")

but not worked.

here xsl.

    <ul>       <xsl:for-each select="message">         <li>           <xsl:value-of select="./type" />         </li>       </xsl:for-each>     </ul>     total count error:<xsl:value-of select="(count(//error/type &eq; "error"))"/> 

could help?

for start, if want output description of each message element, need reference description element, , not type

  <xsl:for-each select="message">     <li>       <xsl:value-of select="description" />     </li>   </xsl:for-each> 

in terms of adding total errors, expression follows (assuming positioned on parent result element.

<xsl:value-of select="count(message[type = 'error'])"/> 

try xslt

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0">     <xsl:output method="html" indent="yes"/>     <xsl:template match="result">      <ul>       <xsl:for-each select="message">         <li>           <xsl:value-of select="description" />         </li>       </xsl:for-each>     </ul>     total count error:<xsl:value-of select="count(message[type = 'error'])"/><br />     total count warning:<xsl:value-of select="count(message[type = 'warning'])"/><br />     total count information:<xsl:value-of select="count(message[type = 'information'])"/><br />   </xsl:template> </xsl:stylesheet> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -