Results 1 to 2 of 2

Thread: SOAP and XSLT

  1. #1
    zenthanian is offline Junior Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    7

    Default SOAP and XSLT

    So I get a SearchResponse back from Zimbra...

    Code:
    <?xml version="1.0"?>
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    	<soap:Header>
    		<context xmlns="urn:zimbra">
    		...
    		</context>
    	</soap:Header>
    	<soap:Body>
    		<SearchResponse more="0" sortBy="dateDesc" offset="0" xmlns="urn:zimbraMail">
    			<c f="su" id="1701" d="1201545135000" score="1.0" n="2" sf="1201545135000">
    				<su>Message 1 Subject</su>
    				<fr>Body Text 1.</fr>
    				<e d="Jane" t="f" p="John Doe" a="user@zimbra.site.com"/>
    				<m id="1731"/>
    			</c>
    			<c f="su" id="1702" d="1201269623000" score="1.0" n="2" sf="1201269623000">
    				<su>Message 2 subject</su>
    				<fr>Body Text 2.</fr>
    				<e d="Jane" t="f" p="John Doe" a="user@zimbra.site.com"/>
    				<m id="1728"/>
    			</c>
    		</SearchResponse>
    	</soap:Body>
    </soap:Envelope>
    I am having trouble defining a .xsl document to format this SOAP response. I basically want to be able to create a list of unread messages subject/from in plain HTML via XSLT. Are their any examples or tools out there?

  2. #2
    zenthanian is offline Junior Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    7

    Default [SOLVED] SOAP and XSLT (SearchResponse)

    I guess I will just answer my own question ...

    This formats the XML for the query using:
    HTML Code:
    <types>message</types>
    (whereas the xml above was derived by using the default 'c' (conversation) in that case zml:m would be zml:c).

    Code:
    <?xml version="1.0"?>
    
    <xsl:stylesheet 
    	version="1.0" 
    	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    	xmlns:env="http://www.w3.org/2003/05/soap-envelope"  
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:zml="urn:zimbraMail"> 
    	
    	
        <xsl:output method="html" indent="yes"/>
        
        
        <xsl:template match="/">
    		<div class="sideblock">
    			<div>
            	<h2>Inbox</h2><a href="#" class="toggle">+/-</a>
    			</div>
    		<xsl:apply-templates select="//env:Body"/>
        	</div>
        </xsl:template>
        
        
        
        
        <xsl:template match="//env:Body">
    		<xsl:for-each select="//env:Body/*" >
    			<xsl:apply-templates select="//env:Body/*"/>
    		</xsl:for-each>    
        </xsl:template>
    
    
    
        <xsl:template match="zml:SearchResponse">
    <div>
        	<xsl:variable name="childrenCount">
        		<xsl:value-of select="count( zml:m )" />
        	</xsl:variable>
    
    		<xsl:if test="number($childrenCount) = 0">
    			No Results
    		</xsl:if>
    
    
    		<xsl:if test="number($childrenCount) > 0">
    	<dl>
    			<xsl:for-each select="zml:m">
    		
    		<dt>From: <xsl:value-of select="zml:e//@p" /></dt>
    		<dd>Subject: <xsl:value-of select="zml:su" /></dd>
    
    			</xsl:for-each>
    	</dl>
              </xsl:if>
    </div>        
        </xsl:template>
    
    
    	<xsl:template match="//env:Fault">
    		 Error: <xsl:value-of select="env:Reason"/> 
    	</xsl:template>
    
    </xsl:stylesheet>
    Hope this helps... I hope to add more for calendaring.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •