Sorry in advance if the title is too vague.
I have to process several XML files referenced by each other with XSLT and search for certain errors.
My XMLs typically look like this:
<topic>
... some elements ...
<topicref @href="path-to-another-file"/>
... some other elements ...
<figure> ... </figure>
</topic>
And my desired output is:
path-to-a-file:
Errors found
path-to-another-file:
Other errors found
I get the paths from href attributes and I'd like to print a path if there's an error in the corresponding file.
The important parts of my XSLT:
<!-- ingress referenced files -->
<xsl:template match="//*[@href]">
<xsl:apply-templates select="document(@href)/*">
<xsl:with-param name="path" select="@href"/>
</xsl:apply-templates>
<xsl:apply-templates select="./*[@href]">
</xsl:apply-templates>
</xsl:template>
<!-- matching topic elements to check -->
<xsl:template match="topic">
<xsl:param name="path"/>
<xsl:if test=".//figure">
<!-- Right now this is where I print the path of the current file -->
<xsl:value-of select="$path"/>
</xsl:if>
<xsl:apply-templates select="figure">
<xsl:with-param name="path" select="$path"/>
</xsl:apply-templates>
</xsl:template>
<!-- check if there's any error -->
<xsl:template match="figure">
<xsl:param name="path"/>
<xsl:if test="...">
<xsl:call-template name="printError">
<xsl:with-param name="errorText" select="'...'"/>
<xsl:with-param name="filePath" select="..."/>
<xsl:with-param name="elementId" select="..."/>
</xsl:call-template>
</xsl:if>
<xsl:if test="...">
<xsl:call-template name="printError">
<xsl:with-param name="errorText" select="'...'"/>
<xsl:with-param name="filePath" select="..."/>
<xsl:with-param name="elementId" select="..."/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- print error message -->
<xsl:template name="printError">
<xsl:param name="errorText"/>
<xsl:param name="filePath"/>
<xsl:param name="elementId"/>
... print out some stuff ...
</xsl:template>
Where should I print out the path of a file? With this transformation I always write it out if the file has a figure element even when it doesn't contain any mistakes. Like this:
path-to-a-file:
Errors found
path-to-file-with-no-errors:
path-to-another-file:
Other errors found
If I put the part in question elsewhere (i.e. in the error checking or printing template) it gets printed after every figure elements examined or errors printed.
I assume the problem could be solved with variables but I'm new to XSLT so I'm not sure how to go about it.
EDIT:
I need to display the path of the file when I find an error in it but only once, after the first error was found. Errors can be found only in files with figure elements.
I hope this clarifies my problem.