Following up on question How do i pass a dynamic filename to unparsed-text function in xslt?
I have the below snippet of code:
<xsl:variable name="PDFNAME" select="InvoiceIndicators/PdfFileName"/>
<xsl:variable name="vText" select="tokenize(unparsed-text('../data/ebpp/fopinvoices/arn/emfe_afp/sample.txt'),'
')"/>
<xsl:message>value of unparsed-text is <xsl:value-of select="$vText"/> </xsl:message>
<xsl:variable name="PDFFileStatus">
<xsl:for-each select="$vText">
<xsl:if test="contains(.,$PDFNAME)">
<xsl:value-of select="substring-after(.,',')"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:message><xsl:text>PDFFileStatus :</xsl:text> <xsl:value-of
select="$PDFFileStatus"/> </xsl:message>
I am making use of the variable PDFFileStatus in other parts of the codes and and a check to it.
For example in some part of the code i have ,
<xsl:when test="DunningSummary and $PDFFileStatus='Found'">
<xsl:value-of select="generate-id(DunningSummary)"/>
</xsl:when>
The code works perfectly so far. But i have some cases where i dont want to enter the code where i have written the unparsed-text function.
Like wrapping it with an if condition :
<xsl:if test="InvoiceIndicators/LetterTypeCode = 'PU'">
<xsl:variable name="imagename" select="substring(substring-after(InvoiceDetails/InvoiceNumber, '_'), 3, 9)"/>
<xsl:variable name="vText" select="tokenize(unparsed-text(concat('../data/ebpp/fopinvoices/arn/emfe_afp/', $FileName, '.txt')),'
')"/>
<xsl:message>value of unparsed-text is <xsl:value-of select="$vText"/> </xsl:message>
<xsl:variable name="PDFFileStatus">
<xsl:for-each select="$vText">
<xsl:if test="contains(.,$imagename)">
<xsl:value-of select="substring-after(.,',')"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:message><xsl:text>PDFFileStatus :</xsl:text> <xsl:value-of select="$PDFFileStatus"/> </xsl:message>
</xsl:if>
But now i have the issue with the code snippet where i added a check to the variable PDFFileStatus.
How do i handle such case?
Based on the comments you want to use the function
unparsed-text-availablehttps://www.w3.org/TR/xpath-functions-31/#func-unparsed-text-available and then only useunparsed-textif the unparsed-text-available check returns true.