r2 - 13 Feb 2006 - 17:07:33 - PatrickDiamondYou are here: TWiki >  Plugins Web > XmlQueryPlugin > XmlQueryPluginRecipe2
Tags:
, create new tag

XmlQueryPluginRecipe2

List Attachments in the current Web per user

Annotated XSLT Query Text

%XSLTSTART{topic=".*" benchmark="on" cache="off" debug="off" user=%URLPARAM{"user"}% puburl=%PUBURL% }%
 <xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:set="http://exslt.org/sets"
  extension-element-prefixes="set">
The last two arguments on the xsl:stylesheet element include set functions

 <xsl:template match="/twiki">

 <form method="get">
 <input type="submit" value="List Attachments for User"/>
 <select name="user" onchange="submit()">
 <option></option>

Output the html to start a form with a drop down list

  <xsl:for-each select="set:distinct(/twiki/web/topic/data/metadata/fileattachment/@user)">
     <xsl:sort select="."/>
Select a unique list of users, sort them and process each one

     <xsl:choose>
     <xsl:when test=". = $user">
         <option><xsl:attribute name="selected"/><xsl:value-of select="."/></option>
     </xsl:when>
     <xsl:otherwise>
         <option><xsl:value-of select="."/></option>
     </xsl:otherwise>
     </xsl:choose>

When the user matchs the current user output a option tag with a selected attribute


  </xsl:for-each>
  </select>
  </form>

 <table border="1">
 <tr><th>Topic</th><th>Attachment</th><th>User</th><th>Comment</th></tr>
 <xsl:for-each select="/twiki/web/topic/data/metadata/fileattachment[@user=$user]">
Loop over each attachment when the user attribute is equal to the currently select user

   <tr>
   <td>[[<xsl:value-of select="../../@web"/>.<xsl:value-of select="../../@topic"/>]]</td>
Output the webname.topicname

   <td>[[<xsl:value-of select="$puburl"/>/<xsl:value-of select="../../@web"/>/<xsl:value-of select="../../@topic"/>/<xsl:value-of select="@name"/>][<xsl:value-of select="@name"/>]]</td>
   <td><xsl:value-of select="@user"/></td>
   <td><xsl:value-of select="@comment"/></td>
  </tr>
  </xsl:for-each>
  </table>
  </xsl:template>
  </xsl:stylesheet>
%XSLTEND%

XSLT Demo

XmlQuery must be Installed for this demo to work. If %XSLTSTART{}% tag appears XmlQueryPugin is not installed

%XSLTSTART{topic=".*" benchmark="on" cache="on" debug="off" user='' puburl=http://twiki.org/p/pub }% <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:set="http://exslt.org/sets" extension-element-prefixes="set">

<xsl:for-each select="/twiki/web/topic/data/metadata/fileattachment[@user=$user]"> </xsl:for-each>
TopicAttachmentUserComment
<xsl:value-of select="../../../@web"/>.<xsl:value-of select="../../../@name"/>? <xsl:value-of select="@name"/>? <xsl:value-of select="@user"/> <xsl:value-of select="@comment"/>
%XSLTEND%
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback SourceForge.net Logo