Welcome to the Mythicsoft Q&A site for:

- Agent Ransack
- FileLocator Lite
- FileLocator Pro

Please feel free to ask any questions on these products or even answer other community member questions.

Useful Links:

- Contact Us
- Help Manuals
- Mythicsoft Home
0 votes

Do y'all have an .xsl that mimicks Standard Text, with File name, Contents, and Surrounding lines?

Starting from that, I'm reasonably certain I can reverse engineer it into anything else.

asked by (1.4k points)

That shouldn't be too hard. I'll have a look around and see what I can find.

1 Answer

+1 vote
 
Best answer

Save this as a text file (with a .xsl extension) and choose it for the Custom (XSLT) format in the File->Export Results... dialog.

<?xml version="1.0"?>
<!-- Text format Transform
    Copyright (C) Mythicsoft Ltd 2013. All rights reserved.
    
    Produces output very similar to the standard Text output transform
    -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
			xmlns:rslt="http://www.mythicsoft.com/FileLocator_16Aug2005"
           version="1.0">

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:apply-templates select="//rslt:file"/>
  </xsl:template>

  <xsl:template match="rslt:file">
    <xsl:value-of select="rslt:path"/>
    <xsl:value-of select="rslt:name"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:size"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:type"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:type"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:modified"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:lastaccess"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:created"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:contents/@rslt:totalhitcount"/>
    <xsl:text>&#13;&#10;</xsl:text>

    <xsl:apply-templates select="rslt:contents/rslt:line"/>
    <xsl:text>&#13;&#10;</xsl:text>
    
  </xsl:template>


  <xsl:template match="rslt:line">
    <xsl:value-of select="@rslt:number"/>
    <xsl:text>&#32;</xsl:text>
    <xsl:value-of select="rslt:text"/>
    <xsl:text>&#13;&#10;</xsl:text>
  </xsl:template>
  
</xsl:stylesheet>

Removing duplicate lines

The above XSL will produce output very similar to the standard Text output but just like the standard Text output if you include surrounding lines you could end up with duplicate lines, e.g.

1    This is surrounding 
2    This is HIT
3    This is surrounding 
4    This is surrounding 
3    This is surrounding 
4    This is surrounding 
5    This is HIT
6    This is surrounding 
7    This is surrounding 

Lines 3 and 4 are duplicated because they are the surrounding lines following the hit on line 2 but also the surrounding lines preceeding the hit on line 5. To make sure that a line is only output once we generate a key on the line number and test against it using something like this:

<?xml version="1.0"?>
<!-- Text format Transform
	Copyright (C) Mythicsoft Ltd 2013. All rights reserved.
	Produces output of path, file, hits with surrounding lines
	-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
			xmlns:rslt="http://www.mythicsoft.com/FileLocator_16Aug2005"
			version="1.0">

  <xsl:output method="text"/>
  <xsl:key name="line-value" match="rslt:line" use="concat(@rslt:number, ../../rslt:path, ../../rslt:name)" />

  <xsl:template match="/">
    <xsl:apply-templates select="//rslt:file"/>
  </xsl:template>

  <xsl:template match="rslt:file">
    <xsl:value-of select="rslt:path"/>
    <xsl:value-of select="rslt:name"/>
    <xsl:text>&#13;&#10;</xsl:text>
    <xsl:apply-templates select="rslt:contents/rslt:line"/>
    <xsl:text>&#13;&#10;</xsl:text>
  </xsl:template>

  <xsl:template match="rslt:line">
    <xsl:if test="generate-id() = generate-id(key('line-value', concat(@rslt:number, ../../rslt:path, ../../rslt:name)))">
      <xsl:value-of select="@rslt:number"/>
      <xsl:text>&#09;</xsl:text>
      <xsl:value-of select="rslt:text"/>
      <xsl:text>&#13;&#10;</xsl:text>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>
answered by (67k points)

Excellent. Can surrounding lines be captured and shown as well?

Good point. I've removed the test for the 'found' line and so it will export all available lines.

Removing duplicates works all the time with one file, but with multiple files it looks like the XSL is filtering out duplicates across the files rather within a file.

Making the file name part of the key should sort that out. I've modified the answer.

Dude, you rock!

...