Kelly Tessena Keck
Kelly Tessena Keck

Reputation: 215

XSLT Template not being applied

I have the following XML with internal XSLT. Some of the templates are being applied and some of them aren't, and I can't figure out a rhyme or reason.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="#style1"?>
<!DOCTYPE dmodule [
  <!ELEMENT xsl:stylesheet (#PCDATA)>
  <!ATTLIST xsl:stylesheet
    id ID #IMPLIED>
]>
<dmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:nsiv="http://www.pbmassoc.com/nsiv" nsiv:spec-issue="3.0.1">
<?MENTORPATH?>
<?xml-stylesheet type="text/xsl" href="#style1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" id="style1">
        <xsl:template match="/">        
            <html>
                <head>
                    <title>XML Compare</title>
                    <style>
                        table, th, td {
                            border: 1px solid black;
                        }
                        .warning {
                            color: red;
                            font-size: 16pt;
                            font-weight: bold;
                            }
                        .caution {
                            font-size: 14pt;
                            font-weight:bold;}
                    </style>
                </head>
                <body>              
                    <h1>                    
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/modelic"/>-
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/sdc"/>-
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/chapnum"/>-
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/section"/>
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/subsect"/>-
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/subject"/>-
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/discode"/>
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/discodev"/>-
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/incode"/>
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/incodev"/>-
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmc/avee/itemloc"/>: 
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmtitle/techname"/> -  
                        <xsl:value-of select="dmodule/idstatus/dmaddres/dmtitle/infoname"/>
                    </h1>
                    <xsl:apply-templates/>
                </body>
            </html> 
        </xsl:template>
        <xsl:template match = "dmodule/content/refs">
            <br/>
            <table>
                <caption>References</caption>
                <tr>
                    <th>Data Module Code</th>
                    <th>Title</th>
                </tr>
                <xsl:apply-templates select = "dmodule/content/refs/refdm"/>
            </table>
        </xsl:template>
        <xsl:template match = "dmodule/content/refs/refdm">
            <tr>
                <td>
                    <xsl:value-of select="avee/modelic"/>-<xsl:value-of select="avee/sdc"/>-<xsl:value-of select="avee/chapnum"/>-
                    <xsl:value-of select="avee/section"/><xsl:value-of select="avee/subsect"/>
                    -<xsl:value-of select="avee/subject"/>-<xsl:value-of select="avee/discode"/><xsl:value-of select="avee/discodev"/>-
                    <xsl:value-of select="avee/incode"/><xsl:value-of select="avee/incodev"/>
                    -<xsl:value-of select="avee/itemloc"/>
                </td>
                <td>
                    <xsl:value-of select="dmtitle/techname"/> - <xsl:value-of select="dmtitle/infoname"/>
                </td>
            </tr>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/reqconds">
            <br/>
            <table>
                <caption>Pre-Requisites</caption>
                <tr>
                    <th>Data Module Code</th>
                    <th>Title</th>
                </tr>
                <xsl:apply-templates select = "dmodule/content/proced/prelreqs/reqconds/reqcondm"/>
            </table>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/reqconds/reqcondm">
            <tr>
                <td>
                    <xsl:value-of select="refdm/avee/modelic"/>-<xsl:value-of select="refdm/avee/sdc"/>-
                    <xsl:value-of select="refdm/avee/chapnum"/>-<xsl:value-of select="refdm/avee/section"/>
                    <xsl:value-of select="refdm/avee/subsect"/>-<xsl:value-of select="refdm/avee/subject"/>
                    -<xsl:value-of select="refdm/avee/discode"/><xsl:value-of select="refdm/avee/discodev"/>-
                    <xsl:value-of select="refdm/avee/incode"/><xsl:value-of select="refdm/avee/incodev"/>
                    -<xsl:value-of select="refdm/avee/itemloc"/>
                </td>
                <td>
                    <xsl:value-of select = "reqcond"/>
                </td>
            </tr>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/supequip">
            <br/>
            <table>
                <caption>Support Equipment</caption>
                <tr>
                    <th>Nomenclature</th>
                    <th>Manufacturer Code</th>
                    <th>Part Number</th>
                </tr>
                <xsl:apply-templates select = "dmodule/content/proced/prelreqs/supequip/supeqli/supequi"/>
                <xsl:apply-templates select = "dmodule/content/proced/prelreqs/supequip/nosupeq"/>
                <xsl:if test = "not(dmodule/content/proced/prelreqs/supequip)">
                    <tr>
                        <td colspan = "3">No Support Equipment</td>
                    </tr>
                </xsl:if>   
            </table>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/supequip/supeqli/supequi">
            <tr>
                <td><xsl:value-of select = "nomen"/></td>
                <td><xsl:value-of select = "identno/mfc"/></td>
                <td><xsl:value-of select = "identno/pnr"/></td>
            </tr>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/supequip/nosupeq">
            <tr>
                <td colspan = "3">No Support Equipment</td>
            </tr>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/supplies">
            <br/>
            <table>
                <caption>Consumables</caption>
                <tr>
                    <th>Nomenclature</th>
                    <th>Manufacturer Code</th>
                    <th>Part Number</th>
                </tr>
                <xsl:apply-templates select = "dmodule/content/proced/prelreqs/supplies/supplyli/supply"/>
                <xsl:apply-templates select = "dmodule/content/proced/prelreqs/supplies/nosupply"/>
                <xsl:if test = "not(dmodule/content/proced/prelreqs/supplies)">
                    <tr>
                        <td colspan = "3">No Consumables</td>
                    </tr>
                </xsl:if>
            </table>
        </xsl:template>
        <xsl:template match = "xsl:stylesheet"/>
        <xsl:template match = "dmodule/content/proced/prelreqs/supplies/supplyli/supply">
            <tr>
                <td><xsl:value-of select = "nomen"/></td>
                <td><xsl:value-of select = "identno/mfc"/></td>
                <td><xsl:value-of select = "identno/pnr"/></td>
            </tr>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/supplies/nosupply">
            <tr>
                <td colspan = "3">No Consumables</td>
            </tr>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/spares">
            <br/>
            <table>
                <caption>Spares</caption>
                <tr>
                    <th>Nomenclature</th>
                    <th>Manufacturer Code</th>
                    <th>Part Number</th>
                </tr>
                <xsl:apply-templates select = "dmodule/content/proced/prelreqs/spares/sparesli/spare"/>
                <xsl:apply-templates select = "dmodule/content/proced/prelreqs/spares/nospares"/>
                <xsl:if test = "not(dmodule/content/proced/prelreqs/supplies)">
                    <tr>
                        <td colspan = "3">No Spares</td>
                    </tr>
                </xsl:if>
            </table>
        </xsl:template>
                <xsl:template match = "dmodule/content/proced/prelreqs/spares/sparesli/spare">
            <tr>
                <td><xsl:value-of select = "nomen"/></td>
                <td><xsl:value-of select = "identno/mfc"/></td>
                <td><xsl:value-of select = "identno/pnr"/></td>
            </tr>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/prelreqs/safety">
                    <br/>
                    <h2>Safety</h2>
                    <xsl:apply-templates select = "warning"/>
                    <xsl:apply-templates select = "caution"/>
                    <xsl:apply-templates select = "note"/>
        </xsl:template>
        <xsl:template match = "warning">
            <p class = "warning">WARNING</p>
                <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match = "para">
            <p><xsl:value-of select = "."/></p>
        </xsl:template>
        <xsl:template match = "caution">
            <p clas = "caution">Caution</p>
            <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match = "note">
            <p class = "note">Note</p>
            <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/mainfunc">
            <h2>Procedure</h2>
            <ol>
                <xsl:apply-templates/>
            </ol>
        </xsl:template>
        <xsl:template match = "dmodule/content/proced/mainfunc/step1">
            <li><xsl:value-of select = "para"/></li>
        </xsl:template>
        <xsl:template match = "idstatus"/>
        <xsl:template match = "closereqs">
            <br/>
            <table>
                <caption>Close-Up Requirements</caption>
                <tr>
                    <th>Data Module</th>
                    <th>Requirement</th>
                </tr>
                <xsl:apply-templates select = "reqconds"/>
                <xsl:choose>
                    <xsl:when test = "not(dmodule/content/proced/closereqs)">
                        <tr>
                            <td colspan = "2">No Close-Up Requirements</td>
                        </tr>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:apply-templates select = "noconds"/>
                    </xsl:otherwise>
                </xsl:choose>
            </table>
        </xsl:template>
        <xsl:template match = "noconds">
            <tr>
                <td colspan = "2">No Close-Up Requirements</td>
            </tr>
        </xsl:template>
        <xsl:output method="html"/>
    </xsl:stylesheet>


    <idstatus>
        <dmaddres>
            <dmc>
                <avee>
                    <modelic>XYZ</modelic>
                    <sdc>AA</sdc>
                    <chapnum>01</chapnum>
                    <section>3</section>
                    <subsect>4</subsect>
                    <subject>11</subject>
                    <discode>02</discode>
                    <discodev>A</discodev>
                    <incode>520</incode>
                    <incodev>A</incodev>
                    <itemloc>A</itemloc>
                </avee>
            </dmc>
            <dmtitle>
                <techname>XYZ Device</techname>
                <infoname>Removal</infoname>
            </dmtitle>
            <issno inwork="11" issno="000" type="new"/>
            <issdate day="05" month="22" year="2009"/>
            <language country="US" language="en"/>
        </dmaddres>
        <status>
            <rpc rpcname="Acme">1234</rpc>
            <orig>1234</orig>
            <applic>
                <displaytext>ALL</displaytext>
            </applic>
            <brexref>
                <refdm>
                    <avee>
                        <modelic>XYZ</modelic>
                        <sdc>AA</sdc>
                        <chapnum>05</chapnum>
                        <section>0</section>
                        <subsect>2</subsect>
                        <subject>20</subject>
                        <discode>35</discode>
                        <discodev>A</discodev>
                        <incode>015</incode>
                        <incodev>A</incodev>
                        <itemloc>C</itemloc>
                    </avee>
                </refdm>
            </brexref>
            <qa>
                <firstver type="tabtop"/>
                <secver type="tabtop"/>
            </qa>
            <remarks>
                <p>Ref Designator: </p>
            </remarks>
        </status>
    </idstatus>
    <content>
        <refs>
            <refdm>
                <avee>
                    <modelic>XYZ</modelic>
                    <sdc>AA</sdc>
                    <chapnum>01</chapnum>
                    <section>1</section>
                    <subsect>1</subsect>
                    <subject>10</subject>
                    <discode>10</discode>
                    <discodev>A</discodev>
                    <incode>100</incode>
                    <incodev>A</incodev>
                    <itemloc>C</itemloc>
                </avee>
                <dmtitle>
                    <techname>Pre-Maintenance Checklist</techname>
                    <infoname>Pre-Operation</infoname>
                </dmtitle>
            </refdm>
            <reftp>
                <pubcode>XYZ-7</pubcode>
                <pubtitle>Installation and Repair Practices </pubtitle>
            </reftp>
        </refs>
        <proced>
            <prelreqs>
                <reqconds>
                    <reqcondm>
                        <reqcond>Pre-Maintenance Checklist</reqcond>
                        <refdm>
                            <avee>
                                <modelic>XYZ</modelic>
                                <sdc>AA</sdc>
                                <chapnum>01</chapnum>
                                <section>1</section>
                                <subsect>1</subsect>
                                <subject>10</subject>
                                <discode>10</discode>
                                <discodev>A</discodev>
                                <incode>100</incode>
                                <incodev>A</incodev>
                                <itemloc>C</itemloc>
                            </avee>
                            <dmtitle>
                                <techname>Pre-Maintenance Checklist</techname>
                                <infoname>Pre-Operation</infoname>
                            </dmtitle>
                        </refdm>
                    </reqcondm>
                </reqconds>
                <reqpers>
                    <person man="2"/>
                </reqpers>
                <supequip>
                    <supeqli>
                        <supequi>
                            <nomen>Lift</nomen>
                            <identno>
                                <mfc>123</mfc>
                                <pnr id="d6791e219" nsiv:sfield="pnr pnrsupeq">301–781</pnr>
                        </identno>
                        <qty>1</qty>
                        </supequi>
                        <supequi>
                            <nomen>Screwdriver</nomen>
                            <identno>
                                <mfc>113</mfc>
                                <pnr id="d6791e229" nsiv:sfield="pnr pnrsupeq">01534343</pnr>
                            </identno>
                            <qty>1</qty>
                        </supequi>
                    </supeqli>
                </supequip>
                <supplies>
                    <nosupply/>
                </supplies>
                <spares>
                    <nospares/>
                </spares>
                <safety>
                    <safecond>
                        <warning><para>Heavy lift involved.</para></warning>
                    </safecond>
                </safety>
            </prelreqs>
            <mainfunc>
                <step1>
                    <para>Disconnect the thing from the other thing.</para>
                </step1>
                <step1>
                    <para>Remove nut (u), lock washer (v), and four flat washers (w).</para>
                </step1>
                <step1>
                    <para>Loosen  fasteners (x).</para>
                </step1>
                <step1>
                    <warning>
                        <para>Two people shall support component when handling component. Failure to comply 
                        could result in personnel injury and damage to equipment.</para>
                    </warning>
                    <para>Lift and remove the heavy thing.</para>
                </step1>
            </mainfunc>
            <closereqs>
                <reqconds>
                    <noconds/>
                </reqconds>
            </closereqs>
        </proced>
    </content>
</dmodule>

The output I get in Chrome looks like this:

XYZ- AA- 01- 34- 11- 02A- 520A- A: XYZ Device - Removal

References Data Module Code Title

Pre-Requisites Data Module Code Title

Support Equipment Nomenclature Manufacturer Code Part Number No Support Equipment

Consumables Nomenclature Manufacturer Code Part Number No Consumables

Spares Nomenclature Manufacturer Code Part Number No Spares

Safety Procedure 1. Disconnect the thing from the other thing. 2. Remove nut (u), lock washer (v), and four flat washers (w). 3. Loosen fasteners (x). 4. Lift and remove the heavy thing.

Close-Up Requirements Data Module Requirement No Close-Up Requirements

The items that aren’t appearing the way I expect them to are the support equipment ("supequi" element), the warnings ("warning" element), the references ("refdm" element) and the required conditions ("reqcondm" element).

Upvotes: 0

Views: 371

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167561

I suspect that in places like <xsl:template match = "dmodule/content/proced/prelreqs/supequip"> you then don't want to use <xsl:apply-templates select = "dmodule/content/proced/prelreqs/supequip/supeqli/supequi"/> but rather a path relative to the matched element, like <xsl:apply-templates select = "supeqli/supequi"/>.

Upvotes: 1

Related Questions