0
votes

I could not find any existing posts that answered this specific problem. Hopefully it is an easy answer for someone more familiar with XSL: I have a XSL stylesheet that is applied to a XML file generated by a part inspection software system, which then reads the resulting HTML code....

I would like to add an external XML file that contains tolerances for each different part number. So i was imagining the XSL sheet would need to use a document() reference with either the document name or an element in the document defined by the name of an element from the source XML file. Hopefully the included code illustrates what i am trying to do. Obviously it does not work as it stands and is also only a snippet of the whole file....

Thanks for any help or links to something I can learn from.

<xsl:variable name="pname">
    <xsl:value-of select="//NAME/."/>.xml
</xsl:variable>

<xsl:template match="TUBE_LRA_ERRORS">
<table border="0" style="font-size:18pt">
    <tr><th><xsl:copy-of select="//NAME/."/></th></tr>
    <tr><th><xsl:value-of select="//REPORT/REPORT_TIME"/></th></tr>
    <tr><th>LRA Errors</th></tr>
</table>
<table border="1" style="font-size:26pt">
<tr align="center" bgcolor="#cccccc">
    <td>#</td><td>L</td><td>R</td><td>A</td>
</tr>
<xsl:for-each select="ERROR">
    <tr>
        <td><xsl:value-of select="position()"/></td>
        <xsl:choose>
            <xsl:when test="X > document('$pname')/l/hi">
                <td bgcolor="00FFFF" style="font-weight:600">
            <xsl:value-of select="X"/></td>
            </xsl:when>
            <xsl:when test="X > document('tolerances.xml')/l/lo">
                <td bgcolor="ffffff" style="font-weight:200">
                    <xsl:value-of select="X"/></td>
            </xsl:when>
        <xsl:otherwise>
1

1 Answers

0
votes

So what you have in mind is that the variable pname will have the name of the tolerances file and you want to check values from that? It should be possible to do so.

This will not work:

<xsl:when test="X > document('$pname')/l/hi">
   <td bgcolor="00FFFF" style="font-weight:600">
        <xsl:value-of select="X"/>
   </td>
</xsl:when>

because you have "$pname" in quotes and this would cause it to look for a file called "$pname". However, this would load the file whose name is the value of $pname (note I've removed the single quotes around $pname:

<xsl:when test="X > document($pname)/l/hi">
   <td bgcolor="00FFFF" style="font-weight:600">
        <xsl:value-of select="X"/>
   </td>
</xsl:when>

Or if you wanted to use a file whose name was the value of $pname plus ".xml", you could do this:

<xsl:when test="X > document(concat($pname, '.xml'))/l/hi">
   <td bgcolor="00FFFF" style="font-weight:600">
        <xsl:value-of select="X"/>
   </td>
</xsl:when>

I think you may have a logic error here:

<xsl:when test="X > document('tolerances.xml')/l/lo">
  <td bgcolor="ffffff" style="font-weight:200">
    <xsl:value-of select="X"/>
  </td>
</xsl:when>

I'm guessing you want to show the special formatting when X is less than the lo value, in which case you would need:

<xsl:when test="X &lt; document('tolerances.xml')/l/lo">