xsl-list
[Top] [All Lists]

RE: template match for subelement throughout tree

2003-04-14 15:54:11
Hi Kathy,

Try replacing all of your <xsl:value-of select="."/> with <xsl:apply-templates 
/>

An xsl:value-of will return the concatenated text nodes of that element's 
subtree with the markup removed and I think you want to apply the templates you 
have defined rather than just extract the text nodes.

Also you might want to look at removing most if not all of your <xsl:for-each 
select="..."> loops and replacing them with <xsl:apply-templates select="...">

HTH,

Ken Ross
Ph: +61 7 32359370
Mob: +61 (0)419 772299
Email: Ken(_dot_)Ross(_at_)iie(_dot_)qld(_dot_)gov(_dot_)au


-----Original Message-----
From: Kathy Burke [mailto:Kathy_Burke(_at_)Jabil(_dot_)com]
Sent: Friday, 11 April 2003 9:31 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] template match for subelement throughout tree


Thanks, Ross. I have 3 tables...Safety, Tools, Steps. Within Safety and
Tools I have numbered_list/listitems/para. I want them to number the way
there are now, but also want to use para to apply a consistent style
(font,size) to all text. When I look at the html result, there are no <p>
tags...seems silly, just can't seem to see what I'm missing.  --Kathy

*************************************
XSL:

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">  
        <xsl:output method="html"/>     
        <!-- ========================================================= -->

        <!--  Standard On-Line Work Instruction Stylesheet 4/10/03     -->

        <!-- ========================================================= -->

        <xsl:template match="/">                
                <html>                  
                        <head>                          
                        <style type="text/css">
                        h1 {font-family: Verdana;color: blue;font-size:20pt
font-weight:bold}
                        h2 {font-family: Verdana;color: red;font-size:18pt
font-weight:bold}
                        h3 {font-family: Verdana;color:
white;font-size:14pt;font-weight:bold}
                        body {font-family: Verdana;color:
black;font-size:10}
                        p {font-family: Verdana;color: black;font-size:14}

                        h4 {font-family: Verdana;color:
white;font-size:10pt;font-weight:bold;text-transform: uppercase}
                        h5 {font-family: Verdana;color:
white;font-size:10pt;font-weight:bold}
                        h6 {font-family: Verdana;color:
black;font-size:10pt;font-weight:bold}
                        </style>
                                <title>Example of XSLT</title>

                        </head>                 
                        <body bgcolor="#DDDDDD">

                                <h1><xsl:value-of
select="/work_instruction/title"/></h1>                         
                                <form method="POST">

                                        <xsl:apply-templates/>

                                        <p align="center">

                                                <a
href="process_steps.asp">Go to Next Procedure</a>

                                        </p>                            
                                </form>                 
                        </body>         
                </html> 
        </xsl:template>
        
        <xsl:template match="safety">           
                <table border="1" width="100%" cellpadding="4">

                        <tr bgcolor="red" valign="bottom">

                                <th align="left">

                                        <h3>SAFETY</h3>

                                </th>                   
                        </tr>                   
                        <xsl:for-each select="numbered_list/listitem">

                                <tr>                                    
                                        <td>

                                                <xsl:number level="multiple"
format="1. " count="listitem" />

                                                <xsl:value-of select="." />

                                        </td>                           
                                </tr>                   
                        </xsl:for-each>         
                </table>                
                <br />  
        </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><b>Jabil Part No.</b></td>

                        </tr>                   
                        <xsl:for-each select="numbered_list/listitem">

                                <tr>                                    
                                        <td><xsl:number level="multiple"
format="1. " count="listitem" />

                                                <xsl:value-of select="."
/></td>
                                        <td>&#160;</td>

                                </tr>                   
                        </xsl:for-each>         
                </table>                
                <br />  
        </xsl:template> 
                
        <xsl:template match="process_steps"> 
                <table border="1" cellpadding="4">
                <tr bgcolor="blue" valign="middle">
                                <th align="left" colspan="2">
                                        <h3>PROCESS STEPS</h3>
                                </th>
        
                        <xsl:apply-templates/>
                        </tr>
                </table> 
        </xsl:template> 
        <xsl:template match="step">  
                <xsl:variable name="space" select="(count(ancestor::step) *
12 + 1) * 7"/>
                <tr>   
                        <td width="5%" valign="top">
                                <xsl:apply-templates
select="@ckbox[.='yes']"/>   
                        </td>   
                        <td valign="top" cellpadding="0">
                                <table width="100%" border="0"
cellpadding="0">
                                        <tr>      
                                                <td cellpadding="0"
valign="top" width="{$space}">
                                                        <table border="0"
cellpadding="0" font-family="Verdana" font-size="14">
                                                                <tr>

                                                                        <td
cellpadding="0" 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="@ckbox">  
                <input type="checkbox">
                        <xsl:if test=".='yes'">
                                <xsl:attribute
name="unchecked">unchecked</xsl:attribute>
                        </xsl:if>  
                </input> 
        </xsl:template> 
        
        <xsl:template match="para">
                <p><xsl:apply-templates/></p>
        </xsl:template>
        
        <xsl:template match="measure">  
                <input type="text" value="{.}"/>&#160;&#160;
                <input type="button" value="Submit"/>
        </xsl:template> 
        
        <xsl:template match="unordered_list">   <!--Need to check this with
para template -->
        <table>
                <tr>
                <td>&#149;</td>
                <td><xsl:for-each select="listitem">
                <xsl:value-of select="."/>
                </xsl:for-each></td></tr>
                </table>
                <xsl:apply-templates select="./para"/>
        </xsl:template>
        

        <!-- format and set html tags for subelements -->
        <xsl:template match="warning">
        <table>
         <tr bgcolor="red" valign="middle">
          <td>
           <h4><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><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><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 href="{(_at_)url}"><xsl:apply-templates/></a>
        </xsl:template>

        <xsl:template match="title"/>
        
</xsl:stylesheet>
*************************************
XML (with just a step or two):

<?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>
<listitem><para>Stencil - See Product Setup Sheet</para></listitem>
<listitem><para>Stencil Wiper Paper</para></listitem>
<listitem><para>Spatula</para></listitem>
<listitem><para>Lint-free Paper Wipes</para></listitem>
</numbered_list>
</tools_materials>
<process_steps>
<step><para>Switching ON the E5 Screen Printer.</para>
<step><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 ckbox="yes"><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><para>Enter <emphasis>test
measurement</emphasis>:</para><measure></measure>
</step>
<step><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><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>
</process_steps>
</work_instruction>


-----Original Message-----
From: Ross Ken [mailto:Ken(_dot_)Ross(_at_)iie(_dot_)qld(_dot_)gov(_dot_)au]
Sent: Thursday, April 10, 2003 7:49 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] template match for subelement throughout tree


A match="para" will match all para elements in your XML document, unless
overridden by a more specific template match.  The // in match="//para" is
irrelevant as far as I am aware.  Normally you only use // in the
select="//para" situation.

If you'd like to send your entire XSLT and a sample XML, I'll have a quick
look at it.

HTH,

Ken Ross
Ph: +61 7 32359370
Mob: +61 (0)419 772299
Email: Ken(_dot_)Ross(_at_)iie(_dot_)qld(_dot_)gov(_dot_)au


-----Original Message-----
From: Kathy Burke [mailto:Kathy_Burke(_at_)Jabil(_dot_)com]
Sent: Friday, 11 April 2003 9:10 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] template match for subelement throughout tree


Thanks, Ken. I thought using "//para" matched ALL occurrences in the doc?
Since I don't even understand what "table[type!='3']/tr/*" does(!!!), I'm
pretty sure I didn't use it!

My structure's pretty simplified at this point, using mostly recursive
templates to apply styles to sublements like <para> and <em>, just don't see
why this itty bitty template doesn't like me.

Kathy

-----Original Message-----
From: Ross Ken [mailto:Ken(_dot_)Ross(_at_)iie(_dot_)qld(_dot_)gov(_dot_)au]
Sent: Thursday, April 10, 2003 6:58 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] template match for subelement throughout tree


The location of the template only matters if there are multiple templates
that match the node.  Could that be the case?  Maybe something like a match
on "table[type!='3']/tr/*" in your stylesheet as well?  

There is a precedence amongst the templates, most specific to least and then
from the bottom of the stylesheet to the top, but I've never fully
understood what determines "most specific", nor trusted the implementation
of this across XSLT processors.

HTH,

Ken Ross
Ph: +61 7 32359370
Mob: +61 (0)419 772299
Email: Ken(_dot_)Ross(_at_)iie(_dot_)qld(_dot_)gov(_dot_)au


-----Original Message-----
From: Kathy Burke [mailto:Kathy_Burke(_at_)Jabil(_dot_)com]
Sent: Friday, 11 April 2003 8:46 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] template match for subelement throughout tree



I'm trying to apply this very simple template:

        <xsl:template match="para">
        <p><xsl:apply-templates/></p>
        </xsl:template>

I have an html structure with an <xsl:apply-templates/> in the body, then I
apply other templates to create 3 tables after that. The <para> template
works within the last table structure but doesn't affect the entire doc...I
would like ALL <para> elements to be effected.

I tried "//para" but clearly am missing something...I though location of the
template didn't matter...just the match node?

Sorry, new at this...

Thanks, Kathy


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

----------------------------------------------------------------------------
----------------------------------------------
IMPORTANT: This email (including any attachments) may contain confidential,
private or legally privileged information and may be protected by copyright.
You may
only use it if you are the person(s) it was intended to be sent to and if
you use it in an
authorised way. No one is allowed to use, review, alter, transmit, disclose,
distribute,
print or copy this e-mail without appropriate authority.
 
If this e-mail was not intended for you and was sent to you by mistake,
please
telephone or e-mail me immediately, destroy any hard copies of this e-mail
and delete
it and any copies of it from your computer system. Any legal privilege and 
confidentiality attached to this e-mail is not waived or destroyed by that
mistake.
 
It is your responsibility to ensure that this e-mail does not contain and is
not affected
by computer viruses, defects or interference by third parties or replication
problems
(including incompatibility with your computer system).




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



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

----------------------------------------------------------------------------
----------------------------------------------
IMPORTANT: This email (including any attachments) may contain confidential,
private or legally privileged information and may be protected by copyright.
You may
only use it if you are the person(s) it was intended to be sent to and if
you use it in an
authorised way. No one is allowed to use, review, alter, transmit, disclose,
distribute,
print or copy this e-mail without appropriate authority.
 
If this e-mail was not intended for you and was sent to you by mistake,
please
telephone or e-mail me immediately, destroy any hard copies of this e-mail
and delete
it and any copies of it from your computer system. Any legal privilege and 
confidentiality attached to this e-mail is not waived or destroyed by that
mistake.
 
It is your responsibility to ensure that this e-mail does not contain and is
not affected
by computer viruses, defects or interference by third parties or replication
problems
(including incompatibility with your computer system).




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



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

Disclaimer:
 
IMPORTANT: This email (including any attachments) may contain confidential,
private or legally privileged information and may be protected by copyright. 
You may
only use it if you are the person(s) it was intended to be sent to and if you 
use it in an
authorised way. No one is allowed to use, review, alter, transmit, disclose, 
distribute,
print or copy this e-mail without appropriate authority.
 
If this e-mail was not intended for you and was sent to you by mistake, please
telephone or e-mail me immediately, destroy any hard copies of this e-mail and 
delete
it and any copies of it from your computer system. Any legal privilege and 
confidentiality attached to this e-mail is not waived or destroyed by that 
mistake.
 
It is your responsibility to ensure that this e-mail does not contain and is 
not affected
by computer viruses, defects or interference by third parties or replication 
problems
(including incompatibility with your computer system).


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