Sometimes you want to print a report of an item and there are no suitable report templates available. One solution is to define a type of universal report template that works for any type of item. 


Below is an example of such a report. It traverses the item structure, in a fixed* number of steps, and prints names, types, description text and attributes of all items it finds. The example also uses a filter to avoid “Reference” parts, since those have no specific meaning and are more likely to include recursive item structures.


XML

<Report>
  <FontStyles> 
    <FontStyle name="Minor" style="italic" font="Segoe UI" size="6"/>
  </FontStyles>

  <Filter name="isNotRef"> 
    <Not>
      <PartTypeEquals sid="IDR"/>
    </Not>
  </Filter> 

  <Text></Text>
  <TimeNow/>                         
  <TableOfContents max_level="3"/>
  
<!-- To control the number of recursion calls-->
<Variable name="PartGroupDepth" as="Integer" select="10"/> 
  
  <Section title="#{Type.Name}: #{Name}">
    <Text font="Minor">SystemWeaver ID: #{Handle} Version: #{Version} Status: #{Status} Date: #{?Now.Format('iso')}</Text>
    <Text/>
    <AttributeTable/>
    <Description/>
  <ApplyTemplate name="PartReport">
  <WithParam name="p1" select="$PartGroupDepth"/>
</ApplyTemplate> 
  </Section>

  <Template name="ItemReportContent">
    <Text font="Minor">SystemWeaver ID: #{Handle} Version: #{Version} Status: #{Status} Date: #{?Now.Format('iso')}</Text>
    <Text/>
    <AttributeTable/>
    <Description/>
  </Template>

  <Template name="PartReport">
  <Parameter name="p1" as="Integer"/> 
    <ForEachPartGroup>
      <ForEachPart>
        <If filter="isNotRef">
          <Section title="#{Type.Name}/#{DefObj.Type.Name}: #{Name}">
            <DefObj>
              <ApplyTemplate name="ItemReportContent"/>
             <If test="$p1 != 0"> 
    <ApplyTemplate name="PartReport">  
    <WithParam name="p1" select="$p1 - 1"/>
    </ApplyTemplate>
  </If>
            </DefObj>
          </Section>
        </If>
      </ForEachPart>
    </ForEachPartGroup>
  </Template>
</Report>


Result


* This kind of report cannot use item templates, since traversing all part types may result in “endless loops”. (The swExplorer will terminate at a fixed number of iterations, in order to avoid such loops)