0

I have the following XSLT:

<xsl:template match="Table">
    <tr>
        <td>
            <font face="Verdana" color="#ffffff" size="2" style="vertical-align: top; white-space: nowrap">
                <xsl:value-of select="PRG_DESCRIPTION"/>
            </font>
        </td>
        <td>
            <font face="Verdana" color="#ffffff" size="2" style="vertical-align: top; white-space: nowrap">
                <xsl:value-of select="DAYS_LEFT"/>
            </font>
        </td>
        <td>&#160;&#160;</td>
        <xsl:if test="ACTIVE = 0">
        <td style="top: 2px">
            <form name="myform"  onsubmit="popupform(this, 'join');"  action="../LogOnSection/SetCourseStart.aspx" method="post">                   
                <input type="hidden" name="CourseID">
                <xsl:attribute name="value">
                    <xsl:value-of select="EEDO_COURSE_ID"/>
                </xsl:attribute></input>
                <input type="hidden" name="UserID"><xsl:attribute name="value">
                    <xsl:value-of select="CLI_RID"/>
                </xsl:attribute></input>
                <input type="hidden" name="EventCode"><xsl:attribute name="value">
                    <xsl:value-of select="EVE_EVENT_CODE"/>
                </xsl:attribute></input>
                <input type="hidden" name="DateCreated">
                <xsl:attribute name="value">
                    <xsl:value-of select="DATE_CREATED"/>
                </xsl:attribute>
                </input>
                <input name="Submit" type="submit" value="Go"/>
                <br>
                </br>
            </form>
        </td>
        </xsl:if>
    </tr>
</xsl:template>

What I need to do is read an XML file and only show records where the code id's in the XML file are not present in the EVE_EVENT_CODE.

The XML file will be something like this:

<?xml version="1.0"?>
    <program_codes>
        <code id="FUN">CR</code>
        <code id="HAN">CR</code>
        <code id="AO">CR</code>
        <code id="RME">CR</code>
        <code id="AD">CR</code>
    </program_codes>

XSLT is one thing that I am not even closely good at and I need help on this desperately.

Update, modified entire sheet:
Is the xsl:if correct?

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="refDoc" value="document('ListCoursesFilter.xml')" />
<xsl:variable name="refIDs" value="$refDoc/program_codes/code/@id" />
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>National Alliance OnLine Courses</title>
                <script TYPE="text/javascript">

                    function popupform(myform, windowname)
                    {
                        var CourseDT = myform.DateCreated.value
                        var CourseDTtoString = CourseDT.substr(0, 4);

                        if (CourseDTtoString == "2007")
                        {
                            window.open('', windowname, 'height=544,width=790,toolbar=no,menubar=no,titlebar=no,scrollbars=yes');
                            myform.target = windowname;
                            return true;
                        } else {
                            window.open('', windowname, 'height=712,width=1014,toolbar=no,menubar=no,titlebar=no,scrollbars=yes');
                            myform.target = windowname;
                            return true;
                        }
                    }
                </script>
            </head>
            <body style="background-repeat: no-repeat; top: 0px">
                <p>
                <table align="center" border="0" style="; width: 569px; height: 89px">
                    <tbody>
                        <tr>
                            <font face="Verdana" size="2">To allow pop up windows from our site, hold down the control key and click "GO"</font><br /><br />
                            <!-- <font face="Verdana" size="3" color="#660000">The CISR, CSRM and William T. Hold self-paced online courses and examination site will be unavailable due to maintenance between the hours of 6:00 a.m. and 10:00 a.m. Central Time on Tuesday, June 17, 2014.  If you need additional assistance please contact us at online@scic.com.</font><br /> -->
                            <!-- <font face="Verdana" size="3" color="#660000">Self-Paced courses will be unavailable due to maintenance June 4th, 2014 at 5:00 pm Central time till Friday morning June 6th, 2014. We are happy to extend your course timeframe to compensate for this closure. Please email <a href="mailto:cisronline@scic.com">cisronline@scic.com</a> with your request for a timeframe extension.</font> -->
                        </tr>
                        <tr>
                            <th>
                                <p align="left">
                                    <font face="Verdana" size="2">Programs</font>
                                </p>
                            </th>
                            <th>
                                <p align="left">
                                    <font face="Verdana" size="2">Course Available Through</font>
                                </p>
                            </th>
                            <th>
                                <p align="left">
                                    <font face="Verdana"/>
                                </p>
                            </th>
                        </tr>
                        <xsl:apply-templates select="/NewDataSet/Table"/>
                    </tbody>
                </table>
                </p>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="Table">
        <tr>
            <td>
                <font face="Verdana" color="#ffffff" size="2" style="vertical-align: top; white-space: nowrap">
                    <xsl:value-of select="PRG_DESCRIPTION"/>
                </font>
            </td>
            <td>
                <font face="Verdana" color="#ffffff" size="2" style="vertical-align: top; white-space: nowrap">
                    <xsl:value-of select="DAYS_LEFT"/>
                </font>
            </td>
            <td>&#160;&#160;</td>
            <xsl:if test="ACTIVE = 0 && count($refIDs[contains(current()/EVE_EVENT_CODE, .)]) = 0">
            <td style="top: 2px">
                <form name="myform"  onsubmit="popupform(this, 'join');"  action="../LogOnSection/SetCourseStart.aspx" method="post">                   
                    <input type="hidden" name="CourseID">
                    <xsl:attribute name="value">
                        <xsl:value-of select="EEDO_COURSE_ID"/>
                    </xsl:attribute></input>
                    <input type="hidden" name="UserID"><xsl:attribute name="value">
                        <xsl:value-of select="CLI_RID"/>
                    </xsl:attribute></input>
                    <input type="hidden" name="EventCode"><xsl:attribute name="value">
                        <xsl:value-of select="EVE_EVENT_CODE"/>
                    </xsl:attribute></input>
                    <input type="hidden" name="DateCreated">
                    <xsl:attribute name="value">
                        <xsl:value-of select="DATE_CREATED"/>
                    </xsl:attribute>
                    </input>
                    <input name="Submit" type="submit" value="Go"/>
                    <br>
                    </br>
                </form>
            </td>
            </xsl:if>
        </tr>
    </xsl:template>
</xsl:stylesheet>

This is how it is "loaded" from the DB, the GM.AlasData.ActiveOLCourses is a web service function that queries our DB for active courses for the passed ParticipantID

s = New StringReader(GM.AlasData.ActiveOLCourses(ParticipantID))
xtr = New XmlTextReader(s)

Dim XMLDoc = New XPathDocument(xtr)
Dim XSLTDoc = New XslCompiledTransform

XSLTDoc.Load(Server.MapPath("ListCourseFormat.xslt"))

'Transform XMLDoc and dump HTML results to stringwriter -> sw
XSLTDoc.Transform(XMLDoc, Nothing, sw)

BTW, looks like it is using v1.0

MB34
  • 4,210
  • 12
  • 59
  • 110
  • So you have two XML files, right? How does the primary input look like, which elements in there do you consider a "record" to show? Do you have various `Table` elements and want to process only those having a `EVE_EVENT_CODE` present in the second? Do you use XSLT 1 or 2? – Martin Honnen Mar 07 '17 at 09:05
  • I don't know what version is being used. The data comes from a DB and is converted to XML. No, I only want to show ones that **do not** have the `id` in the `EVE_EVENT_CODE` – MB34 Mar 07 '17 at 15:11
  • **1.** Show us the raw XML data. **2.** Find out which processor you use: http://stackoverflow.com/questions/25244370/how-can-i-check-which-xslt-processor-is-being-used-in-solr/25245033#25245033 – michael.hor257k Mar 07 '17 at 15:31

1 Answers1

0

As far as I understood you want to output only those <Table> elements where the <EVE_EVENT_CODE> value is not mentioned in that secondary "program_codes" XML document.

<!-- open extra XML document -->
<xsl:variable name="refDoc" value="document('path/to/program_codes.xml')" />

<!-- collect your IDs from that document -->
<xsl:variable name="refIDs" value="$refDoc/program_codes/code/@id" />

<xsl:template match="/">
    <table>
        <!-- process only those nodes where the IDs don't match -->
        <xsl:apply-templates select="//Table[not(EVE_EVENT_CODE = $refIDs)]" />
    </table>
</xsl:template>

<xsl:template match="Table">
    <tr>
        <td style="font: 12pt Verdana; color: white; vertical-align: top; white-space: nowrap">
            <xsl:value-of select="PRG_DESCRIPTION" />
        </td>
        <td style="font: 12pt Verdana; color: white; vertical-align: top; white-space: nowrap">
            <xsl:value-of select="DAYS_LEFT" />
        </td>
        <td>&#160;&#160;</td>
        <xsl:if test="ACTIVE = 0">
            <td style="top: 2px">
                <form action="../LogOnSection/SetCourseStart.aspx" method="post" onsubmit="popupform(this, 'join');">
                    <input type="hidden" name="CourseID" value="{EEDO_COURSE_ID}" />
                    <input type="hidden" name="UserID" value="{CLI_RID}" />
                    <input type="hidden" name="EventCode" value="{EVE_EVENT_CODE}" />
                    <input type="hidden" name="DateCreated" value="{DATE_CREATED}" />
                    <input name="Submit" type="submit" value="Go" />
                    <br />
                </form>
            </td>
        </xsl:if>
    </tr>
</xsl:template>

Hints:

  • Use attribute value templates (the curly braces above) to save yourself quite a lot of typing.
  • Put all the inline styles into a separate CSS file and work with CSS classes. And please drop those <font> tags and erase them from your memory.
  • Spacer columns are not state-of-the-art anymore, either. Work with CSS to get the margins you want, not with <td>&#160;&#160;</td>.

EDIT After a comment from the OP, I suggest the following modified solution:

<!-- open extra XML document -->
<xsl:variable name="refDoc" value="document('path/to/program_codes.xml')" />

<!-- collect your IDs from that document -->
<xsl:variable name="refIDs" value="$refDoc/program_codes/code/@id" />

<xsl:template match="/">
    <table>
        <xsl:apply-templates select="//Table" />
    </table>
</xsl:template>

<xsl:template match="Table">
    <!-- effectively: if there's no refID which is contained in the current event code -->
    <xsl:if test="count($refIDs[contains(current()/EVE_EVENT_CODE, .)]) = 0">
       ...
    </xsl:if>
</xsl:template>
Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • That looks good but the EVE_EVENTCODE may be something like this: `20170204WBRME` or `20170301OLCC` I would need it to match only the first one because `RME` is in the codes and `CC` is not. – MB34 Mar 07 '17 at 20:33
  • This is why you should include your XML instead of vague English descriptions of your XML. How should I have guessed this? – Tomalak Mar 07 '17 at 21:04
  • See modified answer. It should give you the right idea. – Tomalak Mar 07 '17 at 21:15
  • Sorry about the lack of data as I cannot save the data to a file as it is generated from a DB. What do I do about this: ``? See my updated post. – MB34 Mar 08 '17 at 03:06