[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XQuery to Report Template Parameters

Subject: XQuery to Report Template Parameters
From: Eliot Kimber <ekimber@xxxxxxxxxxxx>
Date: Sun, 17 Feb 2008 09:05:05 -0600
 XQuery to Report Template Parameters
Here's my first stab at an XQuery to usefully report all the template parameters in a single XSLT module and their uses. This just generates a convenient XML result but it could be reworked to generate an HTML page, which might be more useful. I also wrote it to handle a single file because I didn't have time to figure out how/remember to set a directory as an input parameter via OxygenXML, which is where I developed it.

I certainly claim no special XQuery expertise, so I would also welcome any feedback on the coding of the query itself.



----- start of query -----
(: Reports template parameters and their uses.

   This query originally developed by W. Eliot Kimber,
   ekimber at reallysi.com. Feel free to adapt, extend
   or distribute as you choose.

declare namespace xsl="http://www.w3.org/1999/XSL/Transform";

declare function local:getTemplateLabel($template as element()) as xs:string {
if ($template/@name != '') then concat(' name="',string($template/@name), '"') else '',
if ($template/@match != '') then concat(' match="', string($template/@match), '"') else '')

declare function local:echoNodes($nodes as node()*) as node()* {
  for $node in $nodes
      return typeswitch($node)
       case $a as element() return local:echoElement($node)
       default return $node

declare function local:echoElement($elem as element()) as element() {

  if (namespace-uri($elem) = "http://www.w3.org/1999/XSL/Transform")
     then element{name($elem)}{$elem/@*, local:echoNodes($elem/node())}
     else element{name($elem)}{$elem/@*, local:echoNodes($elem/node())}

declare function local:reportWithParam($param as element()) as node()* {
{if ($param/@select != '')
then string($param/@select)
else $param/node()
{local:getTemplateLabel($param/ancestor::xsl:template[1]), ':&#x0a; ', local:echoElement($param/..)

let $doc := .

let $templateParams := $doc/*/xsl:template/xsl:param
let $apply-templates := $doc/*/xsl:template[descendant::xsl:apply-templates/xsl:with-param]
let $call-templates := $doc/*/xsl:template[descendant::xsl:call-template/xsl:with-param]

<param-report xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
for $param in $templateParams
order by $param/@name
return <param>
<datatype>{if (string($param/@as) != '') then string($param/@as) else 'xs:anyType'}</datatype>
<default>{if (string($param/@select) != '') then string($param/@select) else '{None}'}</default>
<tunneling>{if ($param/@tunnel = 'yes') then 'Yes' else 'No'}</tunneling>
{ if ($param/../@name != '')
then for $call in $call-templates//xsl:call-template[(string(./@name) = string($param/../@name)) and (xsl:with-param[string(@name) = string($param/@name)])]
return <call>{local:getTemplateLabel($call/ancestor::xsl:template[1]), ':&#x0a; ', local:echoElement($call)}</call>
else (),

for $use in $apply-templates[.//xsl:apply-templates/xsl:with-param[string(@name) = string($param/@name)]]
return <apply>{local:getTemplateLabel($use)}</apply>
for $param in $apply-templates//xsl:apply-templates/xsl:with-param
order by $param/@name
return local:reportWithParam($param)
for $param in $call-templates//xsl:call-templates/xsl:with-param
order by $param/@name
return local:reportWithParam($param)
---- end of query ----
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 610.631.6770

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.