hoping for help with xsl search loop
Posted: Thu Oct 04, 2018 4:01 am
I have a tokenized variable that contains list of filenames from a .txt of a directory listing. I want to look for those filenames in a number of xml files in a number of subdirectories. If the filename is found, I want to output that "filename" was found in "xmlfile".
There are a lot of xml directories and they are not static. Same with xml files. The filenames are not tagged in the xml, so I'm just looking for their plain text occurence in the file.
I'm using an academic version of Oxygen XML so I think I have Saxon through that and I have the standalone Saxon file for running this from the command line.
I've gotten this far, which doesn't work. I know it's broken, but I don't know how to fix it!
Any suggestions? Clearly I am an XSL novice. Thanks for your patience.
There are a lot of xml directories and they are not static. Same with xml files. The filenames are not tagged in the xml, so I'm just looking for their plain text occurence in the file.
I'm using an academic version of Oxygen XML so I think I have Saxon through that and I have the standalone Saxon file for running this from the command line.
I've gotten this far, which doesn't work. I know it's broken, but I don't know how to fix it!
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:h="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xs"
version="3.0"
expand-text="yes"
>
<xsl:variable name="filenames_from_directory_listing" as="xs:string" select="unparsed-text('filenames_from_directory_listing.txt')"/>
<xsl:variable name="filenames_to_find" select="tokenize($filenames_from_directory_listing, '\s+')"/>
<xsl:template match="/">
<xsl:for-each select="collection('.?select=*.xml;recurse=yes')"/>
<xsl:variable name="xml_filenames" select="."/>
<xsl:for-each select="$filenames_to_find">
<xsl:if test="(contains($t, .))">
<xsl:message>{document-uri($xml_filenames)} contains {.}</xsl:message>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>