Re: [xsl] how to remove a "wrapper" element?

Subject: Re: [xsl] how to remove a "wrapper" element?
From: "Mike Haarman" <mhaarman@xxxxxxxxxxxxxxxxxx>
Date: Fri, 27 Jun 2003 14:18:48 -0500
Kathy,

I didn't read the stylesheet too closely, but it looks as though the template
matching step only relies upon ancestor::step or self::step axis statements so
you may well be able to get away with simply adding a template matching substep
that merely applies templates on a selection of child step elements.  As long as
there are no tests or patterns which rely on the position of step elements as
first-order descendants of steps you should be fine.  Did you try?

<xsl:template match="substep">
  <xsl:apply-templates select="step"/>
</xsl:template>

But you might want to consider rewriting parts of the stylesheet as the substep
container *may* allow you to simplify some of the logic, easing maintenance.

hth,

Mike

----- Original Message ----- 
From: "Kathy Burke" <Kathy_Burke@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, June 27, 2003 1:35 PM
Subject: [xsl] how to remove a "wrapper" element?


> Hi.
>
> My xml (as mentioned is posts of yore) uses the following basic structure:
>
> <process_steps>
>    <step/>
>        <step/>
>    <step/>
> </process_steps>
>
> To make authoring easier, the powers that be have added a "wrapper" element
> to the dtd/xml structure as follows:
>
> <process_steps>
>    <step>
>       <substeps>
>           <step/>
>           <step/>
>       </substeps>
>    </step>
> </process_steps>
>
> I've been using a stylesheet (built from much input from this list,
> especially Americo), that serves everything up in a very nice table,
> numbered outline, indented, etc.
>
> QUESTION:  How would I apply a template to remove the <substeps> element
> BEFORE the <steps> are used in the table structure so that it doesn't throw
> everything off?
>
> Sorry for the length, but I've included the stylesheet, a working example,
> and an example with the <substeps>.
>
> Thank you.  Kathy
>
> ****************XSL***********
> <?xml version="1.0" ?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:output method="html"/>
>
> <!-- ========================================================= -->
>
> <!--  Standard On-Line Work Instruction Stylesheet 6/12/03     -->
>
> <!-- ========================================================= -->
>
> <xsl:template match="/">
> <html>
>    <head>
> <style type="text/css">
> bgcolor="#FFFFFF"
> h1 {font-family: Verdana;color: blue;font-size:20pt
> font-weight:bold;margin-top:0;margin-bottom:0}
> h2 {font-family: Verdana;color: red;font-size:18pt
> font-weight:bold;margin-top:0;margin-bottom:0}
> h3 {font-family: Verdana;color:
> white;font-size:14pt;font-weight:bold;margin-top:0;margin-bottom:0}
> body {font-family: Verdana;color:
> black;font-size:12pt}
> p {font-family: Verdana;color: black;font-size:12pt}
>
> h4 {font-family: Verdana;color:
> white;font-size:12pt;font-weight:bold;text-transform:
> uppercase;margin-top:0;margin-bottom:0}
> h5 {font-family: Verdana;color:
> white;font-size:12pt;font-weight:bold;margin-top:0;margin-bottom:0}
> h6 {font-family: Verdana;color:
> black;font-size:12pt;font-weight:bold;margin-top:0;margin-bottom:0}
> </style>
> <title>Example of XSLT</title>
>
>    </head>
> <body>
> <h1><xsl:value-of
> select="/work_instruction/title"/></h1>
> <form method="POST">
>
> <xsl:apply-templates/>
>
> </form>
> </body>
> </html>
> </xsl:template>
>
> <xsl:template match="safety">
> <table border="1" width="100%" cellpadding="4">
>
> <tr bgcolor="red" valign="middle">
>
> <th colspan="2" align="left">
>
> <h3>SAFETY</h3>
>
> </th></tr>
> <xsl:apply-templates select="numbered_list/listitem"
> mode="safety" />
> </table>
> <br />
> </xsl:template>
> <xsl:template match="listitem" mode="safety">
> <tr><td>
> <table border="0">
>
> <tr>
> <td valign="top"><xsl:number
> level="multiple" format="1. " count="listitem" />&#160;</td>
> <td
> valign="top"><xsl:apply-templates/></td>
> </tr>
> </table>
> </td></tr>
> </xsl:template>
>
> <xsl:template match="tools_materials">
> <table border="1" width="100%" cellpadding="4">
> <tr bgcolor="orange" valign="middle">
>
> <th colspan="3" align="left">
> <h3>TOOLS AND MATERIALS</h3>
> </th></tr>
> <tr><td><b>Tool/Material</b></td><td
> align="center"><b>Jabil Part No.</b></td>
> </tr>
> <xsl:apply-templates select="numbered_list/listitem"
> mode="tools_materials" />
> </table>
> <br />
> </xsl:template>
> <xsl:template match="listitem" mode="tools_materials">
> <tr><td>
> <table border="0">
> <tr>
> <td valign="top"><xsl:number
> level="multiple" format="1. " count="listitem" />&#160;</td>
> <td valign="top"><xsl:apply-templates/></td>
> </tr>
> </table>
> <td valign="top">&#160;</td>
> </td></tr>
> </xsl:template>
>
> <xsl:template match="process_steps">
> <table border="1" width="100%" cellpadding="4">
> <tr bgcolor="blue" valign="middle">
> <th align="left" colspan="4">
> <h3>PROCESS STEPS</h3>
> </th>
> <tr bgcolor="green" valign="middle">
> <td align="center" valign="top">
> <input type="button" name="Start"
> value="START"></input></td>
> <td align="left"><font color="white"><b>Click the START
> button to begin the work instruction.</b></font></td></tr>
>
> <xsl:apply-templates/>
> </tr>
> <tr bgcolor="red" valign="middle">
> <td align="center" valign="top">
> <input type="button" name="Finish"
> value="FINISH"></input></td>
> <td align="left"><font color="white"><b>Click the FINISH
> button when work instruction is complete.</b></font></td></tr>
> </table>
> </xsl:template>
> <xsl:template match="step">
> <xsl:variable name="space" select="(count(ancestor::step) *
> 12 + 1) * 7"/>
> <tr onMouseOver="this.bgColor = '#00FFFF'" onMouseOut
> ="this.bgColor = '#FFFFFF'" >
> <td align="center" valign="top">
> <!-- xsl:apply-templates
> select="@timer[.='yes']"/ -->
> <xsl:attribute
> name="Anomaly"></xsl:attribute>
> <input type="button"
> value="Anomaly"></input>
> </td>
> <td valign="top">
> <table width="100%" border="0"
> cellpadding="0">
> <tr>
> <td valign="top"
> width="{$space}">
> <table border="0"
> cellpadding="0">
> <tr>
> <td
> valign="top" width="{$space}">&#160;&#160;</td>
> <td
> valign="top">
>
> <xsl:number level="multiple" count="step" format="1.1"/>
>
> <xsl:if test="not(ancestor::step)">
>
> <xsl:text>.</xsl:text>
>
> </xsl:if>
>
> <xsl:text>&#160;&#160;</xsl:text>
>
> </td>
> </tr>
> </table>
> </td>
> <td>
> <xsl:apply-templates
> select="*[not(self::step)]"/>
> </td>
> </tr>
> </table>
> </td>
> </tr>
> <xsl:apply-templates select="step"/>
> </xsl:template>
>
> <xsl:template match="@timer">
> <xsl:if test=".='yes'">
> <xsl:attribute name="Start"></xsl:attribute>
> <input type="button" value="Start"></input>
> <xsl:attribute
> name="Finish"></xsl:attribute>
> <td align="center" valign="top">
> <input type="button"
> value="Finish"></input></td>
> </xsl:if>
> <td align="center" valign="top">
> <xsl:attribute
> name="Anomaly"></xsl:attribute>
> <input type="button"
> value="Anomaly"></input></td>
> </xsl:template>
>
>
> <xsl:template match="para">
> <p><xsl:apply-templates/></p>
> </xsl:template>
>
> <xsl:template match="measure">
> <input type="text" name="@name" value="{.}"/>&#160;&#160;
> <input type="button" value="Verify"/>
> </xsl:template>
>
> <xsl:template match="unordered_list">
> <table align="left"><br />
> <xsl:apply-templates select="listitem" mode="ul"/></table>
> </xsl:template>
> <xsl:template match="listitem" mode="ul">
> <tr><td valign="top">&#8226;</td>
> <td valign="top"><xsl:apply-templates select="."/></td></tr>
> </xsl:template>
>
> <!-- format and set html tags for subelements -->
>
> <xsl:template match="warning">
> <table>
>   <tr bgcolor="red" valign="middle">
>     <td>
>    <h4>WARNING: <xsl:value-of select="."/></h4>
>    </td><xsl:apply-templates select="warning"/>
>   </tr>
> </table>
> </xsl:template>
>
> <xsl:template match="caution">
> <table>
>   <tr bgcolor="blue" valign="middle">
>     <td>
>      <h5>CAUTION: <xsl:value-of select="."/></h5>
>    </td><xsl:apply-templates select="caution"/>
>   </tr>
> </table>
> </xsl:template>
>
> <xsl:template match="note">
> <table>
>   <tr bgcolor="yellow" align="middle">
>     <td>
>      <h6>Note: <xsl:value-of select="."/></h6>
>    </td><xsl:apply-templates select="note"/>
>   </tr>
> </table>
> </xsl:template>
>
> <xsl:template match="emphasis">
> <b><xsl:apply-templates/></b>
> </xsl:template>
>
> <xsl:template match="link">
>     <a target="_blank" href="{@url}"><xsl:apply-templates/></a>
> </xsl:template>
>
> <!-- Remove the Title element from content -->
> <xsl:template match="title"/>
>
> </xsl:stylesheet>
>
> ********XML without <substeps>***************
> <?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="KB_test.xsl"?>
> <work_instruction revision="B" doc_control_no="10-MS30-1000-037-B"
> dept="10-ME30">
> <title>EKRA E5 Screen Printer WI</title>
> <safety>
> <numbered_list>
> <listitem><para>Static prevention straps and lab coats must be worn at all
> times.</para></listitem>
> <listitem><para>Vinyl disposable gloves must be worn when handling solder
> paste and cleaning stencil and squeegee blades.</para></listitem>
> <listitem><para>Cotton gloves <emphasis>must be worn</emphasis> when
> handling bare boards to load
> into the Board Loader machine prior to printing.</para></listitem>
> </numbered_list>
> </safety>
> <tools_materials>
> <numbered_list>
> <listitem><para>Solder Paste - See Product Setup Sheet</para></listitem>
> <listitem><para>Squeegee Blades - See Product Setup Sheet</para></listitem>
> </numbered_list>
> </tools_materials>
> <process_steps>
> <step timer="no"><para>Switching ON the E5 Screen Printer.</para>
> <step timer="no"><para>Rotate the Main Switch located on the left side of
> the machine
> to the ON position. (This will supply power to both the machine and operator
> PCs.)</para>
> </step>
> <step timer="no"><para>Allow machine computer and operator computer to
> initialize. (The
> Main Menu appears on the screen. The machine program that was last active
> is loaded automatically. The front cover is unlocked.)</para>
> </step>
> <step timer="no"><para>Enter <emphasis>test measurement</emphasis>:
> <measure/></para>
> </step>
> <step timer="no"><para>Use the arrow keys to select the CONTROL menu item.
> Press the
> ENTER key. (The control unit is switched on; the status field changes to
> green).</para>
> </step>
> <step timer="no"><para>Use the arrow key to select the REFERENCE-DRIVE menu
> item. Press
> the ENTER key. (The field flashes green during reference-drive process and
> remains green after. All the motors, except the transport width motor,
> perform
> a reference drive).</para><para>THIS IS TO TEST THE SUBSEQUENT PARA
> TEMPLATE.</para>
> </step>
> <step timer="no"><para>Setup.</para>
> <step timer="no"><para>Use the arrow key to select the FILE menu item. Press
> the ENTER
> key. (Pop-Up window with a list of available programs displays).</para>
> <step timer="no"><para>This is to test the third level STEP.</para></step>
> </step>
> <step timer="no"><para>Use the up and down arrow keys to select the file for
> the board
> you want to print, then using left and right arrow keys select the LOAD
> field.
> Press the ENTER key. (Screen: NAME OF PROGRAM: LOAD PROGRAMME? YES /
> NO.)</para>
> </step>
> </step>
> </step>
> </process_steps>
> </work_instruction>
>
> ******XML with <substeps>*******
> <?xml version="1.0"?>
> <?xml-stylesheet type="text/xsl" href="KB_substeps_test.xsl"?>
> <!DOCTYPE jabil SYSTEM "C:\Program
> Files\Epic\custom\doctypes\Jabil\Jabil.dtd">
> <?Pub Inc?>
> <jabil>
> <work_instruction revision="D" doc_control_no="10-MS30-1000-016"
> dept="10-MS30">
> <title>Operation of the Universal HSP 4796 Machine</title>
> <safety>
> <numbered_list>
> <listitem><para>Static prevention straps and lab coats must be worn at all
> times.</para></listitem>
> </safety>
> <tools_materials>
> </tools_materials>
> <process_steps>
> <step><para>As illustrated in <link
> url="\\bospubv02\!general\workinstructions\images\10-MS30-1000-016-1.gif">Fi
> gure
> 1</link>, the following describes the HSP 4796 machine.</para>
> <substeps>
> <step><para>Power Breaker Crank is on the front left corner of the machine.
> This switch controls electrical power to the machine.</para>
> </step>
> <step><para>The FOUR TIER LAMP assembly is mounted on top of the machine and
> is used to signal an operator of machine conditions.  For example, the red
> light can be illuminated for all machine stop conditions and the yellow
> light
> can be illuminated for all feeder low conditions.</para>
> </step>
> <step><para>Use the EMERGENCY STOP PALM switch to immediately stop the
> machine.
> The Emergency Stop palm switch controls power to the servo axes. Do not use
> the Emergency Stop switch for routine machine stops.</para>
> <para>To disable power to the servo axes,  push the emergency stop switch
> down. This action is known as palming-down the machine.</para>
> <para>To enable power to the servo axes, turn the emergency stop switch
> clockwise
> and push the ON button.</para>
> </step>
> <step><para>Feeder Carriages C1 (left side) and C2 (right side) are where
> all the feeders are mounted on the machine.</para>
> </step>
> <step><para>Operation Control Panel (<link
> url="\\bospubv02\!general\workinstructions\images\10-MS30-1000-016-2.gif">Fi
> gure
> 2</link>):</para>
> <substeps>
> <step><para><emphasis>Power On (PB1)</emphasis> Supplies power for the
> machine.
> With Main Breaker on, and all emergency stops released, press and hold down
> Power On button, until illuminated, to turn on machine.</para>
> </step>
> <step><para><emphasis>Power Off E-Stop (PB3)</emphasis> Pushing in the
> E-stop
> immediately shuts off power and air supply to the machine.</para>
> </step>
> <step><para><emphasis>Operation/Set-up Key</emphasis> When the "Operation"
> Key is changed to "Set-Up" mode, interlock functions of the safety doors are
> disabled.  This key should ALWAYS be in operation mode unless otherwise
> instructed
> by Engineering or Machine support personnel.</para>
> </step>
> <step><para><emphasis>Start Button (PB5)</emphasis> Starts automatic
> operation
> of the machine.  When illuminated, indicates the machine is in automatic run
> mode.</para>
> </step>
> <step><para><emphasis>Stop Button (PB8)</emphasis> Stops automatic operation
> of the machine. When pressed, the machine will complete building the current
> board and then halt production.</para>
> </step>
> <step><para><emphasis>Pause Button (PB7)</emphasis> Pauses automatic
> operation
> of the machine. When pressed, the machine will finish the current placement
> action and then stop.</para>
> </step>
> <step><para><emphasis>Reset Button (PB9)</emphasis> Releases an error
> condition
> on the machine after the "Clear Alarm" button is pressed on the touch
> screen.</para>
> </step>
> <step><para><emphasis>Move Button (PB6)</emphasis> Used to execute a
> function
> indicated on the touch screen.</para>
> </step>
> <step><para><emphasis>Zero Button (PB11)</emphasis> Used to zero all devices
> on the machine.</para>
> </step>
> <step><para><emphasis>Transfer Button (PB12)</emphasis> Transfers a PCB on
> a conveyor to the next conveyor position.</para>
> </step>
> <step><para><emphasis>SYS Clear Button (PB10)</emphasis> Pressing the System
> Clear button will re-boot machine software.  All axis will return to origin
> position and the current running program will be reset to the
> beginning.</para>
> </step>
> <step><para><emphasis>PNL Change Button (PB13)</emphasis> Activates operator
> panel control to the front or rear of the machine.  When pressed while
> already
> illuminated, control is "locked" to that side of the machine and controls
> can not be accessed from the other side.</para>
> </step>
> <step><para><emphasis>Lock Lamp (LED7)</emphasis> When illuminated,
> indicates
> that a control panel has been locked by an operator.</para>
> </step>
> <step><para><emphasis>Buzzer (BZ1)</emphasis> Sounds an alarm when an error
> condition occurs.</para>
> </step>
> </substeps>
> </step>
> </substeps>
> </step>
> </process_steps>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread